uwsgi
Creation of a simple uWSGI site
_$: apt-get install python-pip python-dev
_$: pip install virtualenv
_$: cd /srv
_$: virtualenv uwsgi
_$: cd uwsgi
_$: . bin/activate
(uwsgi): pip install uwsgi
...
Successfully installed uwsgi
Cleaning up...
(uwsgi): mkdir mysite
(uwsgi): cd mysite
/srv/uwsgi/mysite/test.py:
--------------------------
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return "Hello World"
(uwsgi): uwsgi --http :8080 --wsgi-file test.py
*** Starting uWSGI 1.4.4 (64bit) on [Fri Jan 18 09:27:22 2013] ***
compiled with version: 4.4.5 on 17 January 2013 13:20:55
os: Linux-2.6.32-5-amd64 #1 SMP Sun Sep 23 10:07:46 UTC 2012
nodename: web-a
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /srv/uwsgi/mysite
detected binary path: /srv/uwsgi/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uWSGI http bound on :8080 fd 4
spawned uWSGI http 1 (pid: 2507)
uwsgi socket 0 bound to TCP address 127.0.0.1:33503 (port auto-assigned) fd 3
Python version: 2.6.6 (r266:84292, Dec 26 2010, 22:48:11) [GCC 4.4.5]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1e863f0
your server socket listen backlog is limited to 100 connections
mapped 72392 bytes (70 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x1e863f0 pid: 2506 (default app)
*** uWSGI is running in multiple interpreter mode ***
Go to http://127.0.0.1:8080
and check the hello world web page we just created.
Use Ctrl + C
to stop the uwsgi process.
uWSGI behind a web server
The uWSGI server will be listening at port 3000
. The web server will be listening at port 8080
.
/etc/nginx/nginx.conf:
----------------------
...
#include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
/etc/nginx/sites-available/nginx-uwsgi:
---------------------------------------
upstream app_server {
server 127.0.0.1:3000;
}
server {
listen 8080;
location / {
include uwsgi_params;
uwsgi_pass app_server;
}
}
_$: /etc/init.d/nginx restart
_$: ln -s /etc/nginx/sites-available/nginx-uwsgi /etc/nginx/sites-enabled/
(uwsgi): uwsgi --socket :3000 --wsgi-file test.py
Go to http://127.0.0.1:8080
and check the hello world web page.
uWSGI server restart
(uwsgi_shell1)_$: uwsgi --socket :3000 --wsgi-file test.py --pidfile /tmp/uwsgi.pid
(uwsgi_shell2)_$: uwsgi --reload /tmp/uwsgi.pid