2

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.

Jayen
  • 1,827
  • 3
  • 16
  • 27

2 Answers2

1

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:

http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide#Delegation_To_Daemon_Process

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:

http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#The_Apache_Alias_Directive

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.

Graham Dumpleton
  • 5,990
  • 2
  • 20
  • 19
  • 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 http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#Defining_Application_Groups – Jayen Jul 11 '11 at 03: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. – Graham Dumpleton Jul 11 '11 at 03:32
0

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
    
Jayen
  • 1,827
  • 3
  • 16
  • 27