首页 > 解决方案 > 我如何为 Tornado 框架设置 nginx 上传模块

问题描述

我有一个 Web 服务,它使用 tornado framework.uploaded 文件创建,放置在内存中。我想改为流式传输数据。所以我开始使用nginx 上传模块来传输数据。

我的 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 没有正确重启。

有什么帮助吗?

标签: nginxtornado

解决方案


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

但该user参数不是运行 Nginx 所必需的。默认情况下,Nginx 在nobodyuser下运行。因此,您可以从配置文件中省略该user参数。

最后,www-data在 Ubuntu 中默认存在一个专门用于 Web 服务器的用户。如果这就是您正在运行的,您可以使用它而不必创建新用户:

user: www-data;

推荐阅读