I've got a django 1.1 website I want to run in wsgi (as that seems to be the recommended deployment on apache). I want it to run as the www user (apache is running as www-data). I would ideally like this to work out of http://hostname/~www/ (~www/public_html) as well as http://virtualhostname/. I also want this to work for other users who may later use wsgi. Can I make this happen? I've been staring at docs trying to figure where to start, but I'm having trouble combining userdir and wsgi to let me run ~xxx/public_html/index.wsgi as user xxx, for every user xxx.

  • If any of the existing answers solve the problem for you, you should mark it as accepted.
    – kasperd
    Jan 4 '16 at 10:42
  • ok. i just feel weird marking my own answer as accepted, when Graham's answer was very helpful
    – Jayen
    Jan 4 '16 at 22:46
  • If you found it helpful, you should upvote it as well.
    – kasperd
    Jan 4 '16 at 22:51

For starters look at mod_wsgi daemon mode. That allows you to delegate WSGI applications to run in distinct daemon processes. Those processes can then be made to run as a specified user with no need to be using suxec. See:


For running out of a UserDir configured directory with the user having control of where applications are mounted you cant used WSGIScriptAlias and instead need to use AddHandler method for setting up mod_wsgi. See:


The UserDir directive implicitly supplies the Alias directive so you should only need to worry about the AddHandler directive etc.

Do note however that because of precedence rules in Apache, you likely cannot use WSGIScriptAlias at '/' for the same overall virtual host as may mask the user directories. Just means you need to rely on the AddHandler, with mod_rewrite fixup, if mounting on root of site as described in latter part of that section of the documentation.

Suggest you use the official mod_wsgi mailing list for more detail.

  • So I have to make a daemon process [group] for each user I want to run as? There's no way to do it for all users? I see I can use mod_rewrite to set an environment variable for wsgi to use for choosing the process group at code.google.com/p/modwsgi/wiki/…
    – Jayen
    Jul 11 '11 at 3:05
  • Correct, unfortunately it is a manual process for provisioning each daemon process group. It is on the TODO list to have on demand processes, with ability to do that based on user, but been too busy of late to pursue it. Jul 11 '11 at 3:32

My specific problem was solved in the following way:

  • In the VirtualHost block:

    DocumentRoot /home/www/public_html
    WSGIDaemonProcess ~www user=www group=www
  • In userdir.conf:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/~([^/]+)
    RewriteRule . - [E=URL_USER:~%1]
    WSGIProcessGroup %{ENV:URL_USER}
  • In ~www/public_html/.htaccess

    Options +ExecCGI
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /~www/index.wsgi/$1 [QSA,PT,L]
    RewriteRule ^$ /~www/index.wsgi/$1 [QSA,PT,L]

And some stuff I didn't really need:

  • dir.conf:

    DirectoryIndex index.wsgi
  • wsgi.conf

    AddHandler wsgi-script .wsgi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.