简体   繁体   English

Docker Nginx 带有自定义配置文件:未知指令“服务器”

[英]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.

相关问题 使用自定义 nginx 配置文件启动 nginx docker 容器 - starting nginx docker container with custom nginx config file 如何使用自定义配置运行 Nginx docker 容器? - How to run Nginx docker container with custom config? docker 中 codeigniter 的 Nginx 服务器配置,多个应用程序 - Nginx server config for codeigniter in docker, multiple applications docker 运行命令结束于:nginx:[emerg] 未知指令“events” in /etc/nginx/nginx.conf:1 - docker run command ends up in : nginx: [emerg] unknown directive “events” in /etc/nginx/nginx.conf:1 Docker - Nginx 配置文件更改时自动重新加载 - Docker - Nginx autoreload on config file changes 如何使用自定义Nginx配置官方nginx Docker镜像? - How to use custom Nginx config for official nginx Docker image? 如何使用Docker文件覆盖Nginx默认配置? - How to overwrite nginx default config with docker file? 无法将 proxy_server localhost:3000 连接到 nginx 配置文件(docker-compose 项目) - Cannot connect proxy_server localhost:3000 to nginx config file (docker-compose project) 使用“allow”指令将 nginx 服务器位置的访问权限限制为特定的 Docker 容器 - Restrict access to nginx server location to a specific Docker container with “allow” directive Docker - 我如何重新启动 nginx 以应用自定义配置? - Docker - how do i restart nginx to apply custom config?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM