【发布时间】:2021-05-10 15:33:15
【问题描述】:
我正在尝试实现 Django / Gunicorn / Nginx dockerized。 对于 Django gunicorn 和 postgresql 来说,一切都很好。但是 Nginx 决定不工作。
我制作了一个自定义的 Nginx 配置文件,它给了我错误:
未知指令“服务器”
所以我最大程度地改变了它,用 docker run 代替 docker compose 来尝试。我做了一个 Dockerfile,因为似乎卷挂载不起作用但结果相同。
这里是 dockerfile:
FROM nginx:1.19.0-alpine
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
还有 nginx.conf
server {
listen 80;
location / {
proxy_pass http://127.0.0.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
}
很简单。但是如果我尝试运行这个 docker:
docker build -t nginx .
docker run nginx
还是同样的错误。
这是运行命令的完整日志:
docker-entrypoint.sh: /docker-entrypoint.d/ 不为空,将尝试 执行配置 /docker-entrypoint.sh: 寻找 shell /docker-entrypoint.d/ /docker-entrypoint.sh 中的脚本:正在启动 /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh 10-listen-on-ipv6-by-default.sh:获取校验和 /etc/nginx/conf.d/default.conf 10-listen-on-ipv6-by-default.sh: /etc/nginx/conf.d/default.conf 与软件包版本不同, 退出 /docker-entrypoint.sh:正在启动 /docker-entrypoint.d/20-envsubst-on-templates.sh /docker-entrypoint.sh:配置完成;准备启动 2021/02/06 13:58:21 [emerg] 1#1:未知指令“上游”在 /etc/nginx/conf.d/default.conf:1 nginx: [emerg] 未知指令 /etc/nginx/conf.d/default.conf:1中的“上游”
我花了将近 6 个小时在上面,并且可能阅读了一半的 StackOverflow 却没有结果。
有什么拯救生命的想法吗?
【问题讨论】:
-
猜猜:把
upstream和server放到http块里? -
我刚刚测试了您的示例,对我来说,它确实可以正常工作。我不得不将
web:8080替换为127.0.0.1:8080之类的其他内容,因为web是未知的,但在更改它之后,它就可以工作了(向我显示502 Bad Gateway-消息,正如预期的那样)。 -
@qräbnö 我也试过了。它说未知指令http
-
@SimonLeiß 我更新了我的消息以反映更简单但同样的问题
-
@Tartempion34 我刚刚用新配置重新测试了它,它仍然有效(现在我收到一个不同的错误“400 Bad Request - Request Header Or Cookie Too Large”,但我仍然没有得到你得到的错误)。