无法为 Docker 容器内的 Dancer2 应用程序执行 nginx proxy_pass 指令
Failing to execute nginx proxy_pass directive for a Dancer2 app inside a Docker container
我尝试使用 Docker-compose 编排一个在 starman
上运行的 Dancer2
应用程序。我未能集成 nginx
它因 502 Bad Gateway
错误而崩溃。
我的服务器内部看起来像这样:
*1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.22.0.1,
我的 docker-compose 文件如下所示:
version: '2'
services:
web:
image: nginx
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
links:
- pearlbee
volumes_from:
- pearlbee
pearlbee:
build: pearlbee
command: carton exec starman bin/app.psgi
ports:
- "5000:5000"
environment:
- MYSQL_PASSWORD=secret
depends_on:
- mysql
mysql:
image: mysql
environment:
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_USER=root
我的 nginx.conf
文件如下所示:
user root nogroup;
worker_processes auto;
events { worker_connections 512; }
http {
include /etc/nginx/sites-enabled/*;
upstream pb{
# this the localhost that starts starman
#server 127.0.0.1:5000;
#the name of the docker-compose service that creats the app
server pearlbee;
#both return the same error mesage
}
server {
listen *:80;
#root /usr/share/nginx/html/;
#index index.html 500.html favico.ico;
location / {
proxy_pass http://pb;
}
}
}
你把服务名作为Nginx的upstream
服务器是对的,但是你需要指定端口:
upstream pb{
server pearlbee:5000;
}
在 Compose 为您创建的 Docker 网络中,服务可以通过名称相互访问。此外,您不需要发布端口供其他容器使用,除非您也想从外部访问它们。 Nginx 容器将能够访问您应用程序容器上的端口 5000,您无需将其发布到主机。
我尝试使用 Docker-compose 编排一个在 starman
上运行的 Dancer2
应用程序。我未能集成 nginx
它因 502 Bad Gateway
错误而崩溃。
我的服务器内部看起来像这样:
*1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.22.0.1,
我的 docker-compose 文件如下所示:
version: '2'
services:
web:
image: nginx
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
links:
- pearlbee
volumes_from:
- pearlbee
pearlbee:
build: pearlbee
command: carton exec starman bin/app.psgi
ports:
- "5000:5000"
environment:
- MYSQL_PASSWORD=secret
depends_on:
- mysql
mysql:
image: mysql
environment:
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_USER=root
我的 nginx.conf
文件如下所示:
user root nogroup;
worker_processes auto;
events { worker_connections 512; }
http {
include /etc/nginx/sites-enabled/*;
upstream pb{
# this the localhost that starts starman
#server 127.0.0.1:5000;
#the name of the docker-compose service that creats the app
server pearlbee;
#both return the same error mesage
}
server {
listen *:80;
#root /usr/share/nginx/html/;
#index index.html 500.html favico.ico;
location / {
proxy_pass http://pb;
}
}
}
你把服务名作为Nginx的upstream
服务器是对的,但是你需要指定端口:
upstream pb{
server pearlbee:5000;
}
在 Compose 为您创建的 Docker 网络中,服务可以通过名称相互访问。此外,您不需要发布端口供其他容器使用,除非您也想从外部访问它们。 Nginx 容器将能够访问您应用程序容器上的端口 5000,您无需将其发布到主机。