Why isn't Nginx distributing traffic as a load balancer in a Docker container?
August 27, 2019 09:03PM
I have Nginx v.1.17.3 running in a Docker container to act as a load balancer. While I have gotten it to work in the past with a different version, I have not done it recently with this version. The default.conf file of this Nginx instance has the following content:

server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;

location / {
#root /usr/share/nginx/html;
#index index.html index.htm;
proxy_pass http://backend;
proxy_next_upstream error http_502;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

upstream backend {
server 0.0.0.0:814;
server 0.0.0.0:815;
server 0.0.0.0:816;
}

# End of file


I have Nginx running in containers on ports 814, 815 and 816 respectively.

I can bypass the Nginx load balancer with the port numbers. I want the load balancer to receive all the traffic and distribute it. But when I go to the load balancer via a web user interface, I see this:

An error occurred. Sorry, the page you are looking for is currently unavailable. Please try again later.

If you are the system administrator of this resource then you should check the error log for details.

Faithfully yours, nginx.

When I run "docker ps -a" I see this for the load balancing container:

3ba2bc42d377 nginx "nginx -g 'daemon ..." 24 minutes ago Up 6 minutes 0.0.0.0:80->80/tcp
docker-nginxbalancer8

Does anyone know why it is not distributing traffic and just giving me this error? You would think that the container would not start if there was a significant problem. The image created other containers that work fine. I tried using 127.0.0.1 instead of 0.0.0.0. But the problem was exactly the same. The Docker container has Nginx access logs being sent to standard output and Nginx error logs being sent to standard error. Therefore I cannot figure out what is wrong.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 276
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready