将 uWSGI HTTP 服务器转换为在 Nginx 后面工作
Convert uWSGI HTTP server to work behind Nginx instead
我正在使用 uwsgi --http-socket 127.0.0.1:3031 -w app:app
通过 uWSGI 为我的应用程序提供服务,当我在浏览器中转到 127.0.0.1:3031
时它会起作用。我想使用 Nginx,所以我告诉它 uwsgi_pass
到 url,但现在我收到 502 Bad Gateway 错误。如何将 uWSGI 置于 Nginx 之后?
server {
listen 8080;
server_name 127.0.0.1;
location / {
uwsgi_pass 127.0.0.1:3031;
include uwsgi_params;
}
location /static {
alias /static/folder/location;
}
}
2016/05/16 19:50:09 [error] 6810#0: *4 upstream prematurely closed
connection while reading response header from upstream, client:
127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.1", upstream:
"uwsgi://127.0.0.1:3031", host: "127.0.0.1:8080"
使用socket
,而不是http-socket
。
uwsgi --socket 127.0.0.1:3031 -w app:app
http-socket
使 uWSGI 像使用 HTTP 的 Web 服务器一样工作,如果您使用 Nginx 则不正确,因为它直接理解 uWSGI。
你可以在nginx和uWSGI之间使用http-socket。
例如,如果您使用 uWSGI 启动您的 python 应用程序:
uwsgi --http-socket 127.0.0.1:3031 --wsgi-file application.py --callable app --processes 4 --threads 2 --stats 127.0.0.1:9191
配置 Nginx:
location / {
proxy_pass http://127.0.0.1:3031/;
}
我正在使用 uwsgi --http-socket 127.0.0.1:3031 -w app:app
通过 uWSGI 为我的应用程序提供服务,当我在浏览器中转到 127.0.0.1:3031
时它会起作用。我想使用 Nginx,所以我告诉它 uwsgi_pass
到 url,但现在我收到 502 Bad Gateway 错误。如何将 uWSGI 置于 Nginx 之后?
server {
listen 8080;
server_name 127.0.0.1;
location / {
uwsgi_pass 127.0.0.1:3031;
include uwsgi_params;
}
location /static {
alias /static/folder/location;
}
}
2016/05/16 19:50:09 [error] 6810#0: *4 upstream prematurely closed
connection while reading response header from upstream, client:
127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.1", upstream:
"uwsgi://127.0.0.1:3031", host: "127.0.0.1:8080"
使用socket
,而不是http-socket
。
uwsgi --socket 127.0.0.1:3031 -w app:app
http-socket
使 uWSGI 像使用 HTTP 的 Web 服务器一样工作,如果您使用 Nginx 则不正确,因为它直接理解 uWSGI。
你可以在nginx和uWSGI之间使用http-socket。 例如,如果您使用 uWSGI 启动您的 python 应用程序:
uwsgi --http-socket 127.0.0.1:3031 --wsgi-file application.py --callable app --processes 4 --threads 2 --stats 127.0.0.1:9191
配置 Nginx:
location / {
proxy_pass http://127.0.0.1:3031/;
}