【发布时间】:2019-06-02 02:40:06
【问题描述】:
简而言之,我正在尝试设置一个 nginx 容器来 proxy_pass 到端口 80 上的其他容器。
我正在关注本教程:https://dev.to/domysee/setting-up-a-reverse-proxy-with-nginx-and-docker-compose-29jg
他们描述了一个 docker compose 文件,看起来像这样:
version: '3'
services:
nginx:
image: nginx:latest
container_name: production_nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./nginx/error.log:/etc/nginx/error_log.log
- ./nginx/cache/:/etc/nginx/cache
- /etc/letsencrypt/:/etc/letsencrypt/
ports:
- 80:80
- 443:443
your_app_1:
image: your_app_1_image:latest
container_name: your_app_1
expose:
- "80"
your_app_2:
image: your_app_2_image:latest
container_name: your_app_2
expose:
- "80"
your_app_3:
image: your_app_3_image:latest
container_name: your_app_3
expose:
- "80"
然后在 nginx 配置中,他们根据路径执行 proxy_pass,如下所示:
proxy_pass http://your_app_1:80;
这一切对我来说都很有意义,但是当我让测试节点服务器在端口 80 上侦听时,我收到错误:错误:侦听 EACCES:权限被拒绝 0.0.0.0:80。在节点服务器的 Dockerfile 中,我使用了不同的用户:
USER node
我知道我收到此错误是因为非 root 用户不应该能够绑定到端口 1024 或其他端口以下。而且我知道在容器中以 root 身份运行是不好的做法……那么世界上怎么可能发生这样的事情呢?我觉得我在这里遗漏了一些东西。每次在 nginx 中执行 proxy_pass 时,不必记住服务器正在运行的一些自定义高端口会很好......或者这只是生活中的事实?
【问题讨论】:
标签: docker nginx proxy reverse-proxy