【发布时间】:2019-08-21 11:23:56
【问题描述】:
我正在尝试使用 express.js 和 nginx 作为 Docker 的反向代理。 express 应用程序可以单独使用 docker,但是当我添加 nginx 时,我得到 502 响应。它打印这个:
nginx_1 | 2019/03/30 21:14:04 [error] 6#6: *3 connect() failed (111: Connection refused) while connection to upstream, client: 172.20.0.1, server: localhost, request: "GET / HTTP /1.1”,上游:“http://127.0.0.1:20000/”,主机:“localhost:21000”
docker-compose.yml
version: '3.3'
services:
app:
image: node:latest
volumes:
- ./app:/usr/src/service/app
working_dir: /usr/src/service/app
command: ["node", "app"]
ports:
- 20000:18000
nginx:
image: nginx:latest
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/error.log:/etc/nginx/error_log.log
- ./nginx/cache/:/etc/nginx/cache
ports:
- 21000:80
nginx.conf
events {
}
http {
upstream upstream_server {
server localhost:20000;
}
server {
listen 127.0.0.1;
listen 80;
server_name localhost;
location / {
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://upstream_server;
break;
}
}
}
【问题讨论】: