【问题标题】:docker compose nginx reverse proxy to wrong containerdocker compose nginx 反向代理到错误的容器
【发布时间】:2021-02-06 16:40:21
【问题描述】:

我有一个项目服务器的docker-compose.yml 文件。它包含一个mongo 容器、nginx 服务和一个面板。

我必须将我的服务和面板同时用于测试和主环境。首先我在测试环境中发布,然后在主环境中发布。

在主nginx 上发布后转发请求进行测试,这就是问题所在。

重新启动nginx 可以解决问题,那么如何在每次发布到主环境后不重新启动nginx 来永久解决问题。

docker-compose.yml


    version: '3.7'
    
    services:   main-mongo:
        image: mongo:4.2.3
        container_name: main-mongo
        volumes:
          - mongodb:/data/db
          - mongoconfig:/data/configdb
    
      main_service:
        image: project
        container_name: main_service
        restart: on-failure
        volumes:
          - ./views:/project/views
          - ./public:/project/public
        depends_on:
          - main-mongo
    
      test_service:
        image: test_project
        container_name: test_service
        restart: on-failure
        volumes:
          - ./test_view/views:/project/views
          - ./test_view/public:/project/public
        environment:
          - ENV=test
        depends_on:
          - main-mongo
    
      test_panel:
        image: test_panel
        container_name: test_panel
        restart: on-failure
        environment:
          - ENV=test
        depends_on:
          - main-mongo
    
      main_panel:
        image: panel
        container_name: main_panel
        restart: on-failure
        depends_on:
          - main-mongo
    
      python_backend_test:
        image: python_backend_test
        container_name: python_backend_test
        restart: on-failure
        volumes:
          - /tmp:/tmp
    
      nginx:
        image: nginx:1.17
        container_name: nginx
        restart: on-failure
        ports:
          - 80:80
        volumes:
          - ./nginx:/etc/nginx/conf.d/
          - ./panel_front:/usr/share/panel
        depends_on:
          - main_panel
          - test_panel
          - test_service
          - main_service
        volumes:   mongodb:   mongoconfig:

nginx.conf:

server {
        listen 80;
        listen [::]:80;
        server_name domain.com;
        location /api {
           proxy_pass http://main_panel:3000;
        }
        location /account {
           root /usr/share/panel/live;
           try_files $uri $uri/ /index.html;
        }
        location / {
            proxy_pass http://main_service:3000;
        }
}

server {
        listen 80;
        listen [::]:80;
        server_name test.domain.com;
        location /netflix {
            proxy_pass http://python_backend_test:5000;
        }
        location /api {
            proxy_pass http://test_panel:3000;
        }
        location /account {
           alias /usr/share/panel/test/;
           try_files $uri $uri/ /index.html;
        }
        location / {
            proxy_pass http://test_service:3000;
        }
}

【问题讨论】:

    标签: docker nginx docker-compose


    【解决方案1】:

    我有同样的问题。 我解决了为docker-compose 创建网络的问题。

    【讨论】:

      【解决方案2】:

      为您的项目创建一个网络并将所有容器添加到该网络。

      更清楚的是默认网络。默认网络可能会发生冲突。

      【讨论】:

        猜你喜欢
        • 2018-05-31
        • 1970-01-01
        • 1970-01-01
        • 2021-05-04
        • 2018-03-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-21
        相关资源
        最近更新 更多