Development Long read Configuration
Is your ini file optimized?

Is your ini file optimized?

Building blocks of uWSGI configuration.

21 February 2026 17 min read
Share
X in

Introduction

uWSGI offers hundreds of configuration parameters; powerful but overwhelming for newcomers. The ini file is uWSGI's primary config format; YAML and XML are also supported.

This guide explains the most used parameters by category: app loading, process management, networking, security, and lifecycle.

Recommended production values and common mistakes are noted for each parameter.

Application Loading Parameters

module = myapp.wsgi:application specifies the WSGI callable. chdir changes to project root; virtualenv sets the Python environment. pythonpath adds extra module paths.

lazy-apps = true makes each worker load the app independently; prevents global state sharing. need-app refuses to start if the app cannot load.

[uwsgi]
chdir = /var/www/myproject
virtualenv = /var/www/myproject/venv
module = myproject.wsgi:application
pythonpath = /var/www/myproject
lazy-apps = true
need-app = true

Process and Thread Management

master = true enables the master process; provides worker restart on crash and graceful reload. processes sets worker count; threads sets threads per worker.

enable-threads enables Python thread support; required for Django ORM and some libraries. Single process + many threads saves memory for I/O-bound work.

  • processes: CPU sayısına göre (2*CPU)+1
  • threads: I/O-bound için artırın
  • master: her zaman true
  • enable-threads: Django için zorunlu
[uwsgi]
master = true
processes = 4
threads = 2
enable-threads = true
single-interpreter = true

Network and Socket Parameters

socket creates a unix domain socket; nginx connects via uwsgi_pass. http-socket listens for HTTP directly (socket preferred behind nginx).

chmod-socket and chown-socket let nginx user access the socket. buffer-size can be increased for large request headers.

[uwsgi]
socket = /run/uwsgi/app.sock
chmod-socket = 660
chown-socket = www-data:www-data
buffer-size = 8192
listen = 128

Lifecycle and Cleanup

vacuum = true cleans sockets and pid files on process exit. die-on-term = true ensures clean shutdown on SIGTERM.

max-requests recycles workers after N requests; effective against memory leaks. max-worker-lifetime is a time-based alternative.

[uwsgi]
vacuum = true
die-on-term = true
max-requests = 5000
max-requests-delta = 500
reload-on-rss = 512

Security Parameters

uid and gid are dropped via drop privileges; start as root then switch to www-data. harakiri terminates long-running requests.

limit-as sets memory limit; exceeding workers are killed. disable-logging turns off logs in sensitive environments (not recommended for debug).

master = true, vacuum = true ve die-on-term = true üçlüsünü her üretim ini dosyasında varsayılan yapın.

Reload and Deploy

touch-reload triggers graceful reload on file change. py-autoreload watches .py changes in development (do not use in production).

chain-reload renews workers one by one; zero downtime. stats unix:/run/uwsgi/stats.sock enables metric collection.

[uwsgi]
touch-reload = /var/www/myproject/reload.touch
py-autoreload = 1  # sadece dev
stats = /run/uwsgi/stats.sock
memory-report = true

Conclusion

The uWSGI ini file looks complex at first but parameters fall into logical groups. A basic production ini can start at 20-30 lines and grow as needed.

Keep configuration in version control and test in staging. After changes validate with uwsgi --ini file.ini.