【问题标题】:configuration fail nginx setting for tornadoweb, unknown directive "user"tornadoweb 的配置失败 nginx 设置,未知指令“用户”
【发布时间】:2020-11-06 13:55:21
【问题描述】:

我在 nginx 版本 1.0.0 中遇到了这个错误

nginx: [emerg] unknown directive "user" in /etc/nginx/sites-enabled/
tornado:1

如果我删除用户 www-data,工作进程会出错

nginx: [emerg] unknown directive "worker_processes" in /etc/nginx/
sites-enabled/tornado:1

我在谷歌上搜索过,但仍然一无所获 请帮忙

这是我在站点可用的龙卷风

user www-data www-data;
worker_processes 1;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
    worker_connections 1024;
    use epoll;

}

http {
    # Enumerate all the Tornado servers here
    upstream frontends {
        server 127.0.0.1:8081;
        server 127.0.0.1:8082;
        server 127.0.0.1:8083;
        server 127.0.0.1:8084;
    }

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/nginx/access.log;

    keepalive_timeout 65;
    proxy_read_timeout 200;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1000;
    gzip_proxied any;
    gzip_types text/plain text/html text/css text/xml
               application/x-javascript application/xml
               application/atom+xml text/javascript;

    # Only retry if there was a communication error, not a timeout
    # on the Tornado server (to avoid propagating "queries of death"
    # to all frontends)
    proxy_next_upstream error;

    server {
        listen 8080;

        # Allow file uploads
        client_max_body_size 50M;

        location ^~ /static/ {
            root /var/www;
            if ($query_string) {
                expires max;
            }
        }
        location = /favicon.ico {
            rewrite (.*) /static/favicon.ico;
        }
        location = /robots.txt {
            rewrite (.*) /static/robots.txt;
        }

        location / {
            proxy_pass_header Server;
            proxy_set_header Host $http_host;
            proxy_redirect false;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Scheme $scheme;
            proxy_pass http://frontends;
        }
    }

}

【问题讨论】:

    标签: python nginx


    【解决方案1】:

    可能有点过期,但如果有人偶然发现这里有一个提示:

    可能是配置冲突,请在 /etc/nginx 中检查具有相同指令的 .conf 文件。

    【讨论】:

    • 我不小心将 /etc/nginx/*.conf 包含在 /etc/nginx/nginx.conf 中,导致包含循环。在我听从你的建议后,我发现了递归。谢谢!
    【解决方案2】:

    同样值得检查的是 nginx.conf 是否有“include”行。这很常见并且是冲突的来源。

    例如。

    evan@host:~/$ cat /etc/nginx/nginx.conf | grep include
     include /etc/nginx/mime.types;
     include /etc/nginx/conf.d/.conf;
     include /etc/nginx/sites-enabled/;
    

    在这种情况下,/etc/nginx/sites-enabled/ 中的指令会与 nginx.conf 的内容发生冲突。确保不要在包含的文件之间重复任何内容。

    【讨论】:

      【解决方案3】:

      只想详细说明 Kjetil M. 的答案,因为这对我有用,但我没有立即明白他的意思。直到经过多次尝试后,我才解决了这个问题,并有一个“哦,这就是他的意思”的时刻。

      如果您的 /etc/nginx/nginx.conf 文件和其他配置文件之一 /etc/nginx/sites-enabled/ 使用相同的指令,例如“user”,您将遇到此错误。只需确保只有 1 个版本处于活动状态并注释掉其他版本即可。

      【讨论】:

        【解决方案4】:

        worker_* 指令必须在配置的顶部,即必须在 /etc/nginx/nginx.conf 中

        示例: 我的第一行是:

        user www-data;
        worker_processes 4;
        worker_connections 1024;
        

        如果您想知道有多少工作人员最适合您的服务器,您可以运行以下命令:

        grep processor /proc/cpuinfo | wc -l
        

        这告诉你你有多少核心,对于网站来说,工人多于核心是没有意义的。

        如果您想知道您的工作人员可以处理多少个连接,您可以使用:

        ulimit -n
        

        希望对你有帮助。

        【讨论】:

          【解决方案5】:

          我遇到了同样的错误,但是当我使用 -c 选项启动 nginx 时

          nginx -c conf.d/myapp.conf

          效果很好

          【讨论】:

            【解决方案6】:

            另外,如果您在 Windows 上创建了配置文件并在 Linux 上使用 in,请确保行尾正确(“\r\n”与“\r”)并且该文件不是存储为 unicode。

            【讨论】:

              【解决方案7】:

              在我的情况下,错误消息似乎在user 之前显示了一个空格,即使那里没有空格:

              nginx: [emerg] unknown directive " user" in /etc/nginx/nginx.conf:1
              

              原来我的两个 .conf 文件在文件开头有一个 BOM。删除 BOM 解决了这个问题。

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2023-03-07
                • 1970-01-01
                • 2015-04-10
                • 1970-01-01
                • 1970-01-01
                • 2018-11-23
                • 1970-01-01
                • 2021-05-10
                相关资源
                最近更新 更多