Load balancing using NGINX between sites that are in different docker-containers in the Portainer environment

14 views Asked by At

I am not experienced in this. I need to do load balancing between three sites located on different containers in the Portainer. So far, the problem is the following. I have two containers. There is a website on one of them index.html based on NGINX, the second one hosts NGINX as a proxy server. I want my site to be displayed at the request of localhost:81 - index.html (The site itself opens at the request of localhost:8080, it works). But at the same time, so that the request goes through NGINX. I did what many people do on the Internet. But they don't use containers in the Portainer environment for this.

In the nginx.conf configuration file, which is located in the container at the path etc/nginx/nginx.conf, I added the lines:

server {                
                listen 81;
                 server_name _;
                location / {
                        proxy_set_header Host $host;
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_pass http://localhost:8080;
                      
                }
        }

And the file began to look like this:

worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
server {
                
                listen 81;
                 server_name _;
                location / {
                        proxy_set_header Host $host;
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_pass http://localhost:8080;
                      
                }
        }


    include /etc/nginx/conf.d/*.conf;
   # include /etc/nginx/sites-enabled/*;
}

But when I go to localhost:81, I get an nginx welcome page, but not mine. Can you tell me how to solve this problem?

0

There are 0 answers