Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uwsgi + django via Nginx - uwsgi settings/spawn?

I am leaning towards uwsgi+nginx for my Django app, can anyone share the best method for starting up my uwsgi processes? Does anyone have experience tuning uwsgi?

like image 216
kkubasik Avatar asked Jul 07 '10 09:07

kkubasik


People also ask

Is Nginx required for uWSGI?

Can I then ditch NGINX? uWSGI could be used as a standalone web server in production, but that is not it's intentional use. It may sound odd, but uWSGI was always supposed to be a go-between a full-featured web server like NGINX and your Python files.


2 Answers

Launchd on OSX

Upstart/init on the unices.

uwsgi also has its own process manager, so you can just run that as well.

Tuning:

Check the mailing list, for advice on your particular requirements. Uwsgi is amazing, it is a complete deploy solution.

Nginx above 0.8.40 will build the uwsgi bindings by default, Build nginx, build uwsgi and you are golden.

like image 152
chiggsy Avatar answered Oct 11 '22 08:10

chiggsy


these are the functions i use in my fabfile.py file (check out python fabric if you haven't already):

def start_uwsgi():
    with cd(env.server.uwsgi):
        if(exists('server.pid')):
            stop_uwsgi()
            run('sleep 1')
        run('source venv/bin/activate;uwsgi --ini uwsgi.ini;'))

def stop_uwsgi():
    with cd(env.server.uwsgi):
        if(exists('server.pid')):
            run('source venv/bin/activate;uwsgi --stop server.pid;'))

In my uwsgi.ini file i specify:

[uwsgi]
socket = :{{your_port}}
master = true
vhost = true
no-site = true
processes = 1
enable-threads = true
pidfile = server.pid
daemonize = server.log
auto-procname = true
procname-prefix = servername_

for me the main gotyas were:

  • use the daemonise option if you want to keep the uwsgi server going after you close your terminal/ssh session
  • use vhost to run multiple sites under the same uwsgi instance, which is great if your bottleneck is memory, like mine is with the otherwise fantastic webfaction host
  • pidfile tracks the current instance, enabling you to call uwsgi --stop pidfile, uwsgi --start pidfile
  • procname and procname-prefix/append give a nice name to your process so you can easily single it out using ps -u username | grep some_string
like image 2
alzclarke Avatar answered Oct 11 '22 10:10

alzclarke