You can download the full script here: https://raw.github.com/rochacbruno/web2py/master/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh
On your ubuntu 12.04 server:
$wget https://raw.github.com/rochacbruno/web2py/master/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh
$ chmod +x setup-web2py-nginx-uwsgi-ubuntu.sh
$ ./setup-web2py-nginx-uwsgi-ubuntu.sh
Follow the setup instructions and done!
Optimized script for nginx and uwsgi on ubuntu 12.04
I've installed this script on several machines and after a month of testing I figured out the basic configuration for a performatic uwsgi.
Without this settings uwsgi can be a memory eater. (see the thread about wsgi by Bruce Wade on the web2py list, this script was based on Bruce tips)
Explanations:
THE MOST IMPORTANT FOR WEB2PY
reload-mercy - set the maximum amount of seconds to wait for a worker death during a graceful reload
limit-as limit the address space usage of each uWSGI process using POSIX/UNIX setrlimit()
max-requests 2000 - set the maximum number of requests for each worker. When a worker reaches this number it will get recycled. You can use this option to dumb fight memory leaks (even if reload-on-as and reload-on-rss are more useful for this kind of problem)
reload-on-as recycle a workers when its address space usage is over the limit specified
reload-on-rss Works as reload-on-as but it control the physical unshared memory. You can enable both
no-orphans automatically kill workers without a master process
vacuum - automatically remove unix socket and pidfiles on server exit
I did a lot of tests and on a Linode 1024 machine with Ubuntu 12.04 that is the best setup.
If running a Linode 2048 (or any machine with 2GB RAM) the config can be doubled to:
max-requests - 4000, reload-on-as 512, reload-on-rss 192, limit-as 1024 , processes 8, cpu-affinity 3
It is important: http://lists.unbit.it/pipermail/uwsgi/2011-March/001594.html
Also on nginx.conf it is usefull to set the number of processes/workers - I am using 12
Code
and