如何为Tornado框架设置Nginx上传模块

时间:2018-08-14 11:15:38

标签: nginx tornado

我有一个使用龙卷风框架创建的Web服务。将龙卷风中的文件上传到内存中。我想改为流式传输数据。所以我开始使用nginx upload module来流式传输数据。

我的nginx配置:

user nginx;    
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:8888;
    }
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 80;

    # 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 off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_pass http://frontends;
    }
}

}

我收到此错误:

nginx: [emerg] getpwnam("nginx") failed in /etc/nginx/nginx.conf:1
nginx: configuration file /etc/nginx/nginx.conf test failed

我为nginx上传模块测试了另一种配置,但是nginx.service无法正确重启。

有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

nginx: [emerg] getpwnam("nginx") failed in /etc/nginx/nginx.conf:1

此错误意味着您的系统上不存在名为nginx的用户。但是,您可以为服务器创建一个名为nginx的用户,如下所示:

sudo useradd -r -s /bin/false nginx

代码取自-https://askubuntu.com/a/29364/364011

但是运行Nginx不需要user参数。 By default Nginx runs under nobody user。因此,您可以从配置文件中忽略user参数。

最后,默认情况下,Ubuntu中有一个www-data用户专门用于Web服务器。如果这就是您要运行的内容,则可以使用它,而无需创建新用户:

user: www-data;