Using nginx as a proxy to uWSGI applications, have a lot of benefits.
Nginx is built and optimized as a webserver, where the uWSGI is an application server. Nginx has the benefits of load balancing, request caching, it’s more secure, and it’s good for serving static files as well.
I’m going to provide the code, how to use nginx as a proxy to a uwsgi application, using sockets. This is faster than using the normal HTTP way.
The code below, is an example of a nginx config file, to parse all requests to uwsgi.
server {
listen 80;
server_name example.com
location / {
include uwsgi_params;
uwsgi_pass unix:/tmp/uwsgiapp.sock;
}
}
And below an example of a uWSGI config.ini file
[uwsgi]
chdir = /var/www/uwsgi/
module = api
vacuum = true
cheap = true
master = true
callable = app
workers = 8
socket = /tmp/uwsgiapp.sock
chown-socket=nginx:root
uid = pythonuser
touch-reload = /var/www/uwsgi/touch