[这是在我的本地网络上]
我通过发出以下命令,在端口5000-5004上使用Flask
部署了uwsgi
应用程序:
➤ uwsgi --http :5000 --gevent 1000 --http-websockets --master --wsgi-file app.py --callable app
➤ uwsgi --http :5001 --gevent 1000 --http-websockets --master --wsgi-file app.py --callable app
......
虽然通过导航到localhost:5000
等来访问这些服务器非常快,但是尝试通过Nginx对其进行访问并不是突然起作用。它会继续尝试加载并最终导致504 Gateway Time-out
错误。
Nginx日志读取:
2019/06/08 06:17:30 [error] 2744#2744: *46 upstream prematurely closed connection while reading response header from upstream, client: 192.168.31.54, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://127.0.0.1:5002", host: "192.168.31.54", referrer: "http://192.168.31.54/"
2019/06/08 06:17:30 [warn] 2744#2744: *46 upstream server temporarily disabled while reading response header from upstream, client: 192.168.31.54, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://127.0.0.1:5002", host: "192.168.31.54", referrer: "http://192.168.31.54/"
这是我的NginX配置:
user root;
events{
}
error_log logs/error.log warn;
http{
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 600;
keepalive_requests 30;
access_log off;
server_names_hash_max_size 4096;
underscores_in_headers on;
client_max_body_size 8192m;
proxy_connect_timeout 120;
proxy_send_timeout 120;
proxy_read_timeout 120;
uwsgi_read_timeout 120;
types_hash_max_size 4098;
include /etc/nginx/sites-enabled/*;
}
以下是sites-enabled
中唯一文件的内容:
upstream socketio_nodes{
ip_hash;
server 127.0.0.1:5000;
server 127.0.0.1:5001;
server 127.0.0.1:5002;
server 127.0.0.1:5003;
server 127.0.0.1:5004;
}
server {
server_name localhost;
listen 80;
sendfile on;
client_max_body_size 20M;
keepalive_timeout 120;
root .../portal;
location /static {
alias .../portal/static;
}
location / {
try_files $uri @app;
}
location @app {
uwsgi_pass socketio_nodes;
include uwsgi_params;
}
}
uwsgi_params
文件从一开始就存在,我已经将其内容与Nginx文档中提供的内容进行了匹配。
此外,通过NginX访问时,uwsgi日志不会显示任何更改:
*** Starting uWSGI 2.0.18 (64bit) on [Sat Jun 8 07:36:35 2019] ***
compiled with version: 8.3.0 on 07 June 2019 02:57:03
os: Linux-5.1.4-arch1-1-ARCH #1 SMP PREEMPT Wed May 22 08:06:56 UTC 2019
nodename: anton
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: .../portal
detected binary path: /usr/bin/uwsgi
your processes number limit is 31322
your memory page size is 4096 bytes
detected max file descriptor number: 1024
- async cores set to 1000 - fd table size: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :5004 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:44117 (port auto-assigned) fd 3
Python version: 3.7.3 (default, Mar 26 2019, 21:43:19) [GCC 8.2.1 20181127]
Python main interpreter initialized at 0x561b5c699fb0
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 21036928 bytes (20543 KB) for 1000 cores
*** Operational MODE: async ***
WSGI app 0 (mountpoint='') ready in 35 seconds on interpreter 0x561b5c699fb0 pid: 1230 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 1230)
spawned uWSGI worker 1 (pid: 1283, cores: 1000)
spawned uWSGI http 1 (pid: 1284)
*** running gevent loop engine [addr:0x561b5b30a690] ***
此外,NginX能够很好地加载静态文件。