nginxs docker reverse proxy results in error

  docker, load-balancing, nginx, wordpress

When i run the docker-compose file each wordpress site works good with the DB (can be accessed with 10.0.0.10:9000 and 8000 port.)

The problem starts when i try to use nginx as the load balancer, when i put 10.0.0.10:8080 in the URL the resolved URL goes to http://loadbalancer:9000/ instead of the servers.
This results in the DNS_PROBE_FINISHED_NXDOMAIN error.

I use a custom nginx image with the following nginx.conf and dockerfile:

nginx.conf

upstream loadbalancer {
server 10.0.0.10:8000;
server 10.0.0.10:9000;
}
server {
location / {
proxy_pass http://loadbalancer;
}}

dockerfile

FROM nginx:latest

RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf

docker-compose.yml

version: '3.3'

services:
   db:
     image: mysql_image
     ports:
       - "3306:3306"
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: root
       WORDPRESS_DB_PASSWORD: somewordpress
       WORDPRESS_DB_NAME: wordpress
     volumes:
       - wordpress:/var/www/html

   second_wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "9000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: root
       WORDPRESS_DB_PASSWORD: somewordpress
       WORDPRESS_DB_NAME: wordpress2
     volumes:
       - wordpress2:/var/www/html

   ngnix-server:
     image: my_nginx
     ports:
       - "8080:80"


volumes:
    wordpress:
    wordpress2:

Source: Docker Questions

LEAVE A COMMENT