[英]Docker Nginx with custom config file: unknown directive “server”
I'm trying to implement a Django / Gunicorn / Nginx dockerized.我正在尝试实现一个 Django / Gunicorn / Nginx dockerized。 For Django gunicorn and postgresql everything works very well.
对于 Django gunicorn 和 postgresql ,一切运行良好。 But Nginx decided to not work.
但是 Nginx 决定不工作。
I made a custom Nginx config file which gave me the error:我制作了一个自定义 Nginx 配置文件,它给了我错误:
unknown directive "server"
未知指令“服务器”
So I changed it at the maximum to try it with docker run in place of docker compose.所以我最大程度地改变了它,用 docker 运行代替 docker 组合。 I did a Dockerfile because it seems that the volume mount didn't work but same result.
我做了一个 Dockerfile 因为似乎卷安装不起作用但结果相同。
Here is the dockerfile:这是 dockerfile:
FROM nginx:1.19.0-alpine
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
And the nginx.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;
}
}
Pretty simple.很简单。 But still if I try to run this docker:
但是如果我尝试运行这个 docker:
docker build -t nginx .
docker run nginx
Still the same error.还是同样的错误。
Here is the full logs on the run command:以下是运行命令的完整日志:
docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh 10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf 10-listen-on-ipv6-by-default.sh: /etc/nginx/conf.d/default.conf differs from the packages version, exiting /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh /docker-entrypoint.sh: Configuration complete;
docker-entrypoint.sh:/docker-entrypoint.d/ 不为空,将尝试执行配置 /docker-entrypoint.sh:在 /docker-entrypoint.d/ 中寻找 shell 脚本 /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:配置完成; ready for start up 2021/02/06 13:58:21 [emerg] 1#1: unknown directive "upstream" in /etc/nginx/conf.d/default.conf:1 nginx: [emerg] unknown directive "upstream" in /etc/nginx/conf.d/default.conf:1
准备启动 2021/02/06 13:58:21 [emerg] 1#1:/etc/nginx/conf.d/default.conf:1 nginx 中的未知指令“upstream”:[emerg] 未知指令“upstream” " 在 /etc/nginx/conf.d/default.conf:1
I spend almost 6 hours on that and probably read half of StackOverflow with no result.我花了将近 6 个小时在上面,可能读了一半的 StackOverflow 没有结果。
Any life saving idea?有什么拯救生命的想法吗?
Ok Finally got it.好的 终于明白了。
I removed the complete.conf file and did it without copy paste directly with vim and that works.我删除了 complete.conf 文件,没有直接使用 vim 进行复制粘贴,这很有效。
It seems that PyCharm saved it with a problem.看来 PyCharm 救了它有问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.