[uWSGI] uwsgi and wsgi-based python apps in a shared hosting environment

Roberto De Ioris roberto at unbit.it
Sat Mar 19 09:45:50 CET 2011

> On Fri, Mar 18, 2011 at 1:36 PM, Roberto De Ioris <roberto at unbit.it>
> wrote:

>> Another part is reloading, i suppose you do not give shell access to
>> your
>> users, so every app should monitor the .py file for changes (or probably
>> it is easier to unload the app after every request build a cgi-like
>> system)
> Is this possible?  I think I may need to rethink my approach a little bit
> but I'd like to see where discussion leads.

First of all take the latest tip (it includes a couple of useful fixes for
your specific situation)


location ~ \.py$ {
                include uwsgi_params;
                uwsgi_param UWSGI_FILE $request_filename;
                uwsgi_param UWSGI_TOUCH_RELOAD $request_filename;
                uwsgi_param SCRIPT_NAME $uri;
                if (-f $request_filename) {

UWSGI_FILE will load the specified file
SCRIPT_NAME is the internal name of the new app (the uri will be used as key)
UWSGI_TOUCH_RELOAD specify the file to "stat" for modification time.
Every time it changes, the uWSGI stack is reloaded.

Then spawn uWSGI with at least this options:

./uwsgi -s :3031 -M -i

the master will allow graceful reload, -i will force single interpreter
mode. In this way different .py file (for the same domain) can communicate
each other (they are all parts of the same big virtual app, i bet your
users will find this very handy)


the app is loaded only the first time, it then remains in memory until
modifications (if you want to push some php developer to python this is a
good argument to show :P )

Remember to have one uWSGI instance for domain, i suggest you using unix
socket (something like /xxx/yyy/domainname.sock per each virtualhost)

Do not forget --uid and --gid if you start uWSGI as root

You can use the same instance for all the users using multiple
interpreters but this will introduce a lot of security headache and you
will lose control of memory-usage-per-virtualhost

Let me now if it works flawlessly

Roberto De Ioris

More information about the uWSGI mailing list