L
L
LakeForest2022-03-02 23:32:48
Nginx
LakeForest, 2022-03-02 23:32:48

Why does Nginx (in docker-compose) not balance, then balance, then not again? How to fix?

docker-compose.yaml

service: ...
  nginx:
    image: nginx
    env_file:
      - .env
    depends_on:
      - api
      - backend1
      - backend2
      - backend3
      - backend4
    volumes:
      - ./config/nginx.conf:/etc/nginx/conf.d/default.conf
    ports:
      - ${NGINX_PORT_1}:${NGINX_PORT_1} 
      - ${NGINX_PORT_2}:${NGINX_PORT_2} 
      - ${NGINX_PORT_3}:${NGINX_PORT_3} 
    restart: always

A day ago, I didn’t balance either, it worked when I described nginx.conf in this way and threw it into /etc/nginx/nginx.conf.
When I finished testing, I removed the 2nd instances from upstream. Today I tried to add it again - again it does not work!
worker_processes auto;
error_log /var/log/nginx/error.log;

events {
    worker_connections 1024;
}

http {

    upstream load1{
        server backend1:8001;
        server backend2:8001;
    }

    upstream load2 {
        server backend3:8001;
        server backend4:8001;
    }
    access_log /var/log/nginx/access.log;
    server {
        listen 8558 http2;
        charset utf-8;

        location / {
            grpc_pass grpc://load1;
        }
    }

    server {
        listen 8556 http2;
        charset utf-8;

        location / {
            grpc_pass grpc://load2;
        }
    }

    server {
        listen 8557;
        charset utf-8;

        location /api {
            proxy_pass http://api:8000;
        }

        location /nginx_status {
            stub_status on;
            access_log off;
        }
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question