[This was on my local network]
I have deployed a Flask
application using uwsgi
on ports 5000-5004 by issuing the following commands:
➤ 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
......
While accessing these servers by navigating to localhost:5000
etc. is crazy fast, trying to access it through Nginx isn't working suddenly. It keeps on trying to load and ends up in a 504 Gateway Time-out
error.
Nginx logs read:
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/"
Here is my NginX config:
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/*;
}
Here are the contents of the only file in 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;
}
}
The uwsgi_params
file was there from the beginning and I have matched it's contents to that provided in the Nginx documentation.
Also, when accessing through NginX, uwsgi logs don't show any change:
*** 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] ***
Also, NginX is able to load static files quite fine.