我的操作系统是带有最新 Docker Desktop 的 Windows 10,应用程序在节点 16(docker nodejs) 上运行
这是我的 nginx conf 文件:./nginx/default.conf(windows 10 machine)
server {
listen 80;
location /users {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://pwm-node:3000
proxy_redirect off;
}
}
这是我的 docker-compose.yml:
version: '3'
services:
nginx:
image: nginx:stable-alpine
ports:
- "3000:80" # nginx listen on 80
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
pwm-node:
build: .
environment:
- PORT=3000
depends_on:
- mongo
mongo:
image: mongo
environment:
- MONGO_INITDB_ROOT_USERNAME=superuser
- MONGO_INITDB_ROOT_PASSWORD=superuser
volumes:
- mongo-db:/data/db
redis:
image: redis
volumes:
mongo-db:
这是nginx容器启动失败的日志:
2021-12-20T11:50:31.262794400Z /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
2021-12-20T11:50:31.262861000Z /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
2021-12-20T11:50:31.263500100Z /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
2021-12-20T11:50:31.264787300Z 10-listen-on-ipv6-by-default.sh: info: can not modify /etc/nginx/conf.d/default.conf (read-only file system?)
2021-12-20T11:50:31.264896600Z /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
2021-12-20T11:50:31.266405000Z /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
2021-12-20T11:50:31.267157100Z /docker-entrypoint.sh: Configuration complete; ready for start up
2021-12-20T11:50:31.269871700Z 2021/12/20 11:50:31 [emerg] 1#1: invalid number of arguments in "proxy_pass" directive in /etc/nginx/conf.d/default.conf:11
2021-12-20T11:50:31.269880300Z nginx: [emerg] invalid number of arguments in "proxy_pass" directive in /etc/nginx/conf.d/default.conf:11
最佳答案
这很简单:你在 nginx/default.conf 中缺少一个分号,你必须写:
proxy_pass http://pwm-node:3000;
关于bash - 无法启动 docker nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70421533/