Deploying Web Applications with uWSGI and Nginx

uWSGI serves as the application server for running web applications, while Nginx acts as a reverse proxy and static file server.

uWSGI Configuration

Create a uwsgi.ini file in the same directory as manage.py with the following configuration:

[uwsgi]
socket=127.0.0.1:8000
chmod-socket=666
chdir=/path/to/your/project
wsgi-file=project/wsgi.py
processes=4
threads=2
master=true
pidfile=uwsgi.pid
daemonize=uwsgi.log

The socket directive binds to localhost for security, ensuring external access is handled by Nginx.

Nginx Setup

Install Nginx using package manager:

apt-get install nginx

Or compile from source:

wget http://nginx.org/download/nginx-1.6.2.tar.gz
tar xzvf nginx-1.6.2.tar.gz
cd nginx-1.6.2
./configure
make && make install

Configure Nginx by editing /etc/nginx/nginx.conf and add a server block within the http section:

server {
    listen 80;
    server_name your-server-ip;
    
    location / {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:8000;
    }
    
    location /static {
        alias /path/to/static/files;
    }
}

Nginx efficiently serves static assets, while uWSGI handles dynamic content processing.

Service Management

Handle port conflicts:

sudo killall -9 nginx

Control Nginx service:

service nginx start
service nginx restart
service nginx stop
nginx -t  # Test configuration

Start the application stack:

/usr/local/nginx/sbin/nginx
uwsgi --ini uwsgi.ini

To terminate:

sudo killall -9 nginx
sudo killall -9 uwsgi

With this setup, accessing the server IP through a browser will serve the application.

Tags: uWSGI nginx deployment Django web-server

Posted on Thu, 22 Oct 2026 16:32:08 +0000 by rocksolidhq