§2024-06-04

Ask chatGPT,

I installed the HAProxy, and I would do first is HAPrpxy running on http://munetaka.me:80 will reposnd with a index.html from /home/alexlai/HAProxy directory just to say hello. Please help me with /etc/haproxy/haproxy.cfg.

Here's a basic setup that involves HAProxy forwarding requests to a local Nginx server that serves the index.html file.

¶ Step 1: Install Nginx

sudo apt update
sudo apt install nginx

¶ Step 2: Configure Nginx

server {
    listen 8080;
    server_name localhost;

    location / {
        root /home/alexlai/HAProxy;
        index index.html;
    }
}
sudo ln -s /etc/nginx/sites-available/haproxy_site /etc/nginx/sites-enabled/

¶Step 3: Configure HAProxy

global
    log /dev/log    local0
    log /dev/log    local1 notice
    chroot /var/lib/haproxy
    stats socket /run/haproxy/admin.sock mode 660 level admin
    stats timeout 30s
    user haproxy
    group haproxy
    daemon

defaults
    log     global
    mode    http
    option  httplog
    option  dontlognull
    timeout connect 5000
    timeout client  50000
    timeout server  50000
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 403 /etc/haproxy/errors/403.http
    errorfile 404 /etc/haproxy/errors/404.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502.http
    errorfile 503 /etc/haproxy/errors/503.http
    errorfile 504 /etc/haproxy/errors/504.http

frontend http_front
    bind *:80
    default_backend http_back

backend http_back
    server nginx_server 127.0.0.1:8080 check

¶Step 4: Restart HAProxy