【发布时间】:2020-08-17 05:04:47
【问题描述】:
我有 nginx config 和 docker compose,但我无法将它们正确链接在一起。
default.conf:
worker_processes auto;
events { worker_connections 1024; }
http {
upstream docker_nginx {
server nginx:6000;
}
server {
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://localhost:4000;
proxy_set_header Host $host;
}
location /jwt/user/ {
proxy_set_header X-Forwarded-For $remote_addr;
pproxy_pass http://localhost:4000;
proxy_set_header Host $host;
}
}
}
Docker 撰写:
version: '2'
services:
reverseproxy:
image: nginx
container_name: docker_nginx
ports:
- 6000:6000
volumes:
- ./services:/default.conf
restart: always
jwt:
build: ./jwt
image: jwt:1.0
ports:
- 4000:4000
restart: always
volumes:
- ./jwt
我想监听端口 6000 并将请求路由到端口 4000 上的服务。我尝试运行 http://nginx:6000/ 和 http://localhost:6000/ 但我明白了:
This site can’t be reached. The web page at http://localhost:6000/ might be temporarily down or it may have moved permanently to a new web address.
ERR_UNSAFE_PORT
【问题讨论】:
-
尝试更改端口号而不是 6000 ??
-
@Panther 是的,我试过了,但没有运气
-
你必须明确告诉 nginx 监听 6000 端口,否则默认为 80,因此你必须在 docker-compose 文件中映射
6000:80
标签: node.js docker nginx docker-compose