configuration fail nginx setting for tornadoweb, u

2020-02-28 07:08发布

问题:

I've got this error in nginx version 1.0.0

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

if I remove user www-data the worker processes got error

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

I've search on google but still got nothing please help

this is my tornado in site-available

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

}

回答1:

Probably a bit overdue, but if anyone stumbles on this here's a hint:

Probably config collision, check in /etc/nginx for a .conf file with same directive.



回答2:

Also worth checking, is whether the nginx.conf has an "include" line. It's very common and is a source of collisions.

For example.

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

In this case, a directive in /etc/nginx/sites-enabled/ will clash with the the contents of nginx.conf. Make sure you don't double up on anything between the included files.



回答3:

Just want to elaborate on Kjetil M.'s answer, as that worked for me but I did not get what he means immediately. I wasn't until after a lot of attempts did I fix the problem and had a "oh that's what he meant" momment.

If your /etc/nginx/nginx.conf file and one of other config files /etc/nginx/sites-enabled/ use the same directive such as "user", you will run into this error. Just make sure only 1 version is active and comment out the other ones.



回答4:

worker_* directives must be on the top of configuration, that means must be in /etc/nginx/nginx.conf

Example: My firsts lines are:

user www-data;
worker_processes 4;
worker_connections 1024;

if you want to know how many workers is the best for your server you can run this command:

grep processor /proc/cpuinfo | wc -l

this tell you how many cores do you have, it doesn't make sense to have more workers than cores for websites.

if you want to know how many connections your workers can handle you can use this:

ulimit -n

Hope it helps.



回答5:

I was getting the same error, but when I started nginx with -c options as

nginx -c conf.d/myapp.conf

it worked fine



回答6:

Another thing, if you've created the config file on Windows and are using in on Linux, make sure the line endings are correct ("\r\n" vs. "\r") and that the file is not stored as unicode.



标签: python nginx