首页 > 解决方案 > Docker nginx / 坏网关:使用 docker-compose 的多个应用程序

问题描述

对不起这个问题。我是 docker 和 nginx 的新手。我需要一些帮助

所以,我有一个带有 nginx 代理的 docker 和 3 个带有 3 个不同应用程序的 docker

我根本不知道如何配置 nginx 以避免在我的 3 个应用程序上出现错误的网关错误。你能帮我么?我只能在 1 个应用程序上找到有关此问题的帮助。

我的码头工人撰写

version: '2.1'

services:
    proxy:
        container_name: proxy
        hostname: proxy
        build: .docker/nginx
        ports:
            - "80:80" #80:80
            - "443:443"
        volumes:
            - ./certs:/etc/nginx/certs
            - /var/run/docker.sock:/tmp/docker.sock:ro
        networks:
            - proxy
        restart: always

networks:
    proxy:
        external: true

我的 Docker 文件

FROM jwilder/nginx-proxy
RUN { \
  echo 'client_max_body_size 500M;'; \
} > /etc/nginx/conf.d/my_proxy.conf

应用程序1

version: '3'

services:
    apache:
        build: .docker/apache
        container_name: app1_apache
        environment:
            VIRTUAL_HOST: "app1.local"
        expose:
            - "80"
        volumes:
            - .docker/config/vhosts:/etc/apache2/sites-enabled
            - ../../app1:/var/www/app1.local
        depends_on:
            - php
        networks:
            - default
            - proxy

    php:
        build: .docker/php
        container_name: app1_php
        environment:
            VIRTUAL_HOST: "app1.local"
        volumes:
            - ../../app1:/var/www/app1.local
        networks:
            - default
            - proxy

networks:
    proxy:
        external: true

App2 和 App3的相同文件

我找到了这个解决方案,但我不明白如何实现它。 nginx docker container: 502 bad gateway response 我需要修改 nginx config.d 配置文件,但我不知道该怎么做。

我的默认 config.d 文件

server {
   listen       80;
   server_name  localhost;

   #charset koi8-r;
   #access_log  /var/log/nginx/log/host.access.log  main;

   location / {
       root   /usr/share/nginx/html;
       index  index.html index.htm;
   }

   #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 app1{
  //insert your hosts ip here
  server 192.168.99.100:8080;
}
upstream app2{
  //insert your hosts ip here
  server 192.168.99.100:8080;
}
upstream app3{
  //insert your hosts ip here 
  server 192.168.99.100:8080;
}

nginx 配置对我来说真的很模糊。

谢谢您的帮助

标签: dockernginxdocker-compose

解决方案


推荐阅读