nginx - 我如何为 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 没有正确重启。
有什么帮助吗?
解决方案
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 在nobody
user下运行。因此,您可以从配置文件中省略该user
参数。
最后,www-data
在 Ubuntu 中默认存在一个专门用于 Web 服务器的用户。如果这就是您正在运行的,您可以使用它而不必创建新用户:
user: www-data;
推荐阅读
- mysql - 如何使用 Laravel 查询构建器构建这样的查询?
- google-api - 从 Google Calendar API 获取澳大利亚的假期列表
- javascript - 导入 HTML 元素的更好方法?
- mysql - 如何找到购买相同产品的用户对?
- python - 如何在 booking.com 上使用 scrapy 而不会被阻止?
- docker - 如何使用filebeat或logstash,fluentd读取pod内kubernetes中的stdout stderr日志
- swift - 如何显示特定数据,并在 Firestore 中将其组合在一起
- javascript - js 代码适用于 firefox,但不适用于 chrome opera 和 edge
- java - Java打印双科学记数法,少位数
- itext - 更改文档限制