How can I configure nginx for load balancing Rserver

I am a beginner, I have deployed two Rserver and tried load balancing with nginx server.
However, during the configuration process, I was unable to correctly redirect my access to the nginx server address to the backend server.
How do I configure nginx. conf? Is there a configuration guide website or template?thx a lot.

1 Like

You need to configure nginx.conf to properly proxy requests to your R servers. Here’s a basic setup:

http {
    upstream rserver_backend {
        server rserver1:8787;
        server rserver2:8787;
    }

    server {
        listen 80;
        server_name yourdomain.com;

        location / {
            proxy_pass http://rserver_backend;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
}

Make sure:

  1. Replace rserver1 and rserver2 with your actual backend IPs or hostnames.
  2. Open port 8787 on both R servers.
  3. Restart Nginx after changes: sudo systemctl restart nginx.