tags:

views:

216

answers:

2

I'm running Django on a server with a dozen or so virtual hosts set up. The first Django site I've put together works great, but I'm about to set up a second. Do I need to run a second fastcgi process?

For the first site I'm running fcgi this way:

/home/django/app1/manage.py runfcgi protocol=fcgi host=127.0.0.1 port=8081

The nginx config for the domain points to that fcgi process (fastcgi_pass 127.0.0.1:8081).

For the second site, do I need to run another copy of the fcgi, as in one fcgi per site?:

/home/django/app2/manage/py runfcgi protocol=fcgi host=127.0.0.1 port=8082

And then direct the nginx config to that process (fastcgi_pass 127.0.0.1:8082)?

Or is there some way to handle more than one Django site with a single fastcgi? Is there a best practice for setting up a multi-Django server?

+2  A: 

It depends on what you mean by site, and what your Django configurations look like.

Each Django settings.py defines one and only one database, one and only one urls.py tree.

Each Django has one settings.py -- one database -- one urls.py tree.

If each site has a distinct database, they need distinct settings.py and you'd need a distinct fastcgi instance.

If all sites a supported by a single database, with a single settings.py, then you can squeeze them all out of a single fastcgi instance.

Note that Django's urls.py handler mostly ignores the hostname and port number in the url parsing in the request. However, if you include the Sites model, you can have the virtual host name become part of request processing.

S.Lott
Thank you, that is very helpful.
Jason Champion
A: 

For what it's worth you can do away with the tcp overhead and use a socket instead:

/home/django/app1/manage.py runfcgi protocol=fcgi socket=/var/run/mysite.sock

sockets must be readable and writable for the webserver user.

sleepyjames