Skip to content

Instantly share code, notes, and snippets.

@sumitsk20
Last active January 30, 2024 07:58
Show Gist options
  • Save sumitsk20/021ace4d1c3426618109e9e698eb97f4 to your computer and use it in GitHub Desktop.
Save sumitsk20/021ace4d1c3426618109e9e698eb97f4 to your computer and use it in GitHub Desktop.
uwsgi configuration with most commonly sused options for highly scalable website (medium blog post)
[uwsgi]
# telling user to execute file
uid = bunny
# telling group to execute file
gid = webapps
# name of project you during "django-admin startproject <name>"
project_name = updateMe
# building base path to where project directory is present [In my case this dir is also where my virtual env is]
base_dir = /webapps/%(project_name)
# set PYTHONHOME/virtualenv or setting where my virtual enviroment is
virtualenv = %(base_dir)
# changig current directory to project directory where manage.py is present
chdir = %(base_dir)/src/
# loading wsgi module
module = %(project_name).wsgi:application
# enabling master process with n numer of child process
master = true
processes = 4
# enabling multithreading and assigning threads per process
# enable-threads = true
# threads = 2
# Enable post buffering past N bytes. save to disk all HTTP bodies larger than the limit $
post-buffering = 204800
# Serialize accept() usage (if possibie).
thunder-lock = True
# Bind to the specified socket using default uwsgi protocol.
uwsgi-socket = %(base_dir)/run/uwsgi.sock
# set the UNIX sockets’ permissions to access
chmod-socket = 666
# Set internal sockets timeout in seconds.
socket-timeout = 300
# Set the maximum time (in seconds) a worker can take to reload/shutdown.
reload-mercy = 8
# Reload a worker if its address space usage is higher than the specified value (in megabytes).
reload-on-as = 512
# respawn processes taking more than 50 seconds
harakiri = 50
# respawn processes after serving 5000 requests
max-requests = 5000
# clear environment on exit
vacuum = true
# When enabled (set to True), only uWSGI internal messages and errors are logged.
disable-logging = True
# path to where uwsgi logs will be saved
logto = %(base_dir)/log/uwsgi.log
# maximum size of log file 20MB
log-maxsize = 20971520
# Set logfile name after rotation.
log-backupname = %(base_dir)/log/old-uwsgi.log
# Reload uWSGI if the specified file or directory is modified/touched.
touch-reload = %(base_dir)/src/
# Set the number of cores (CPUs) to allocate to each worker process.
# cpu-affinity = 1
# Reload workers after this many seconds. Disabled by default.
max-worker-lifetime = 300
@dinesh-kapri
Copy link

Hey,
How can we set the max number of logs files to be created?
For Example, If we want to set that the machine will only generate a max of 10 logs files, after that the last generated will be deleted

@sumitsk20
Copy link
Author

Hey,
How can we set the max number of logs files to be created?
For Example, If we want to set that the machine will only generate a max of 10 logs files, after that the last generated will be deleted

@dinesh-kapri you can use logrotate for that

Sample logrotate setup.

$ cd /etc/logrotate.d
$ sudo nano uwsgi
/var/log/uwsgi/*.log {
        daily
        missingok
        rotate 14
        compress
        delaycompress
        notifempty
        copytruncate
        sharedscripts
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment