ยง2024-06-07

# /etc/nginx/sites-enabled/upstream-43887

# Define the upstream server group with weights
upstream backend_servers {
    server h2jammy.yushei.net:43887 weight=3;
    server h2jammy-01.yushei.net:43887 weight=1;
    # This means that h2jammy.yushei.net:43887 will 
    # receive three times more requests than h2jammy-01.yushei.net:43887.
}

server {
    server_name munetaka.me:43887;
    charset utf-8;

    location / {
        proxy_pass http://backend_servers;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-Host munetaka.me;
        # Reflects the port the client connects to
        proxy_set_header X-Forwarded-Port 43887;
        
    }

    listen 43887 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/munetaka.me/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/munetaka.me/privkey.pem; # managed by Certbot
}

I had a nginx reverse proxy running on https://munetaka.me. With a upstream-43887 enabled, so that https://munetaka.me:43887 will reverse proxy to http://http://h2Jammy.yushei.net:43887

# port 43887, http://h2Jammy.yushei.net:43887 Caddy Markdown Dir Server

server {
     server_name  munetaka.me:43887;
     charset utf-8;

     location / {
        proxy_pass http://h2Jammy.yushei.net:43887;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-Host munetaka.me;
        proxy_set_header X-Forwarded-Port 43887;

     }

     listen 43887 ssl; # managed by Certbot
     ssl_certificate /etc/letsencrypt/live/munetaka.me/fullchain.pem; # managed by Certbot
     ssl_certificate_key /etc/letsencrypt/live/munetaka.me/privkey.pem; # managed by Certbot
}

If I also had http://h2jammy-01.yushei.net:43887 as another upsteam server for https://munetaka.me:43887, how to set it up so that,

http://munetaka.me:43887 load balanceing between http://h2jammy.yushei.net:43887 and http://h2jammy-01.yushei.net:43887?