无法启动 docker nginx

Cannot start docker nginx

我的操作系统是 windows 10,带有最新的 Docker 桌面,应用程序是 运行 在节点 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;