Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TornadWeb的nginx设置配置失败,未知指令“;“用户”;_Python_Nginx - Fatal编程技术网

Python TornadWeb的nginx设置配置失败,未知指令“;“用户”;

Python TornadWeb的nginx设置配置失败,未知指令“;“用户”;,python,nginx,Python,Nginx,我在nginx版本1.0.0中遇到了这个错误 nginx: [emerg] unknown directive "user" in /etc/nginx/sites-enabled/ tornado:1 如果删除用户www数据,工作进程将出错 nginx: [emerg] unknown directive "worker_processes" in /etc/nginx/ sites-enabled/tornado:1 我在谷歌上搜索过,但还是一无所获 请帮忙 这是我的龙卷风现场可用 us

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

nginx: [emerg] unknown directive "user" in /etc/nginx/sites-enabled/
tornado:1
如果删除用户www数据,工作进程将出错

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;
        }
    }

}

可能有点晚了,但如果有人无意中发现了这一点,这里有一个提示:


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

我只想详细解释一下杰蒂尔·M.的回答,因为这对我来说很有效,但我没有马上明白他的意思。直到我尝试了很多次之后,我才解决了这个问题,并有了一个“哦,这就是他的意思”的妈妈


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

同样值得检查的是,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的内容冲突。确保所包含的文件之间没有任何重叠。

worker_*指令必须位于配置的顶部,这意味着必须位于/etc/nginx/nginx.conf中

示例: 我的第一行是:

user www-data;
worker_processes 4;
worker_connections 1024;

如果您想知道服务器的最佳工作线程数,可以运行以下命令:

grep processor /proc/cpuinfo | wc -l
这告诉你你有多少个核心,对于网站来说,拥有比核心更多的工作人员是没有意义的

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

ulimit -n

希望有帮助。

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

nginx-c conf.d/myapp.conf


它工作正常

另一件事,如果您在Windows上创建了配置文件,并且在Linux上使用,请确保行尾正确(“\r\n”vs.“\r”),并且文件未存储为unicode。

在我的情况下,错误消息显示在
用户
之前有一个空格,尽管那里没有空格:

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

事实证明,我的两个.conf文件在文件的开头有一个BOM表。删除BOM修复了该问题。

I意外地将/etc/nginx/*.conf包含在/etc/nginx/nginx.conf中,从而导致包含循环。在我听从你的建议后,我发现了递归。谢谢