docker - 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;
}
- 这是正确的 ?
- 我还必须更改proxy_pass吗?
nginx 配置对我来说真的很模糊。
谢谢您的帮助
解决方案
推荐阅读
- mpi - 使用 mpirun 指定哪些进程实现 RQ worker
- java - 我如何知道 JList 中可以显示的行数?
- javascript - 使用 HTML 选项值到达 Javascript 数组元素
- php - Botman 对话不将数据保存到 mysql db
- python - Django 多个数据库 CreateSuperUser - 给出 django.db.utils.IntegrityError: (1048, "Column 'last_login' cannot be null")
- mongodb - 从 MongoDB 获取没有 ObjectId 的 _id
- javascript - 为什么我的 html 值与数组中的任何内容都不匹配?
- tomcat - Tomcat URL 重定向问题
- python - 如何为pytest中的模拟函数提供不同的返回值?
- python - 将顶点总魔术标签问题转换为 SAT