配置失败:Nginx 设置 Tornadoweb,未知指令 "user

9 投票
7 回答
16531 浏览
提问于 2025-04-16 16:13

我在使用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

我在谷歌上搜索过,但还是没有找到解决办法,求助

这是我在site-available里的tornado配置

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

}

7 个回答

2

我想进一步解释一下Kjetil M.的回答,因为他的解决办法对我有效,但我一开始并没有完全明白他的意思。经过很多次尝试后,我终于解决了这个问题,才恍然大悟:“哦,原来他是这个意思。”

如果你的/etc/nginx/nginx.conf文件和其他配置文件/etc/nginx/sites-enabled/中使用了相同的指令,比如“user”,那么你就会遇到这个错误。只需要确保只有一个版本是有效的,其他的可以用#符号注释掉。

4

还值得检查一下,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 文件里的内容发生冲突。确保在包含的文件之间没有重复的内容。

16

可能有点晚了,但如果有人看到这个,可以给你个提示:

很可能是配置冲突,去 /etc/nginx 目录看看有没有同样指令的 .conf 文件。

撰写回答