views:

316

answers:

3

I've been told wsgi is the way to go and not mod_python. But more specifically, how would you set up your multi website server environment? Choice of web server, etc?

+1  A: 

I'd recommend Nginx for the web server. Fast and easy to set up.

You'd probably want to have one unix user per vhost - so every home directory holds its own application, python environment and server configuration. This allows you to restart a particular app safely, simply by killing worker processes that your vhost owns.

Just a tip, hope it helps.

ohnoes
I've been looking for a reason to try out nginx, so i'll hit this up on my local machine. Thanks!
schmilblick
Daemon mode of mod_wsgi allows you to delegate WSGI applications to distinct processes for each virtual host, or even when within same virtual host. You can then force restart of a WSGI application in various ways without having to restart the whole of Apache.
Graham Dumpleton
A: 

You could use Apache and mod_wsgi. That way, you can still use Apache's built-in support for vhosts.

R. Bemrose
+2  A: 

Apache+mod_wsgi is a common choice.

Here's a simple example vhost, setup up to map any requests for /wsgi/something to the application (which can then look at PATH_INFO to choose an action, or however you are doing your dispatching). The root URL '/' is also routed to the WSGI application.

LoadModule wsgi_module /usr/local/lib/mod_wsgi.so
...

<VirtualHost *:80>
    ServerName                  www.example.com
    DocumentRoot                /www/example/htdocs
    WSGIScriptAliasMatch ^/$    /www/example/application.py
    WSGIScriptAlias      /wsgi  /www/example/application.py
</VirtualHost>

You can use the WSGIProcessGroup directive to separate handlers for different vhosts if you like. If you need vhosts' scripts to be run under different users you'll need to use WSGIDaemonProcess instead of the embedded Python interpreter.

application.py would, when run, leave your WSGI callable in the global ‘application’ variable. You can also add a run-as-main footer for compatibility with old-school CGI:

#!/usr/bin/env python
from mymodule import MyApplication

application= MyApplication()

if __name__=='main':
    import wsgiref.handlers
    wsgiref.handlers.CGIHandler().run(application)
bobince
You don't need to use WSGIScriptAliasMatch as given for mounting at root of web site. You can still use WSGIScriptAlias, just have first argument be '/'. WSGIScriptAliasMatch would actually be used quite rarely.
Graham Dumpleton