Matt Seymour
Matt Seymour

Reputation: 9415

Django with Python - webserver

When using django with apache which is the best server config? Should I use mod_wsgi?

At this point no configuration has been completed I only have the application code which has been tested using the local development server built into django.

Would anyone recommend using another web server application such as nginx?

Upvotes: 2

Views: 895

Answers (2)

sergzach
sergzach

Reputation: 6764

The scheme with Apache is a slower then the following. Use uwsgi (read the next please): http://www.jeremybowers.com/blog/post/5/django-nginx-and-uwsgi-production-serving-millions-page-views/

Upvotes: 2

Eduardo Ivanec
Eduardo Ivanec

Reputation: 11862

The Django docs state:

If you’re new to deploying Django and/or Python, we’d recommend you try mod_wsgi first. In most cases it’ll be the easiest, fastest, and most stable deployment choice.

At this point I'd choose Apache + wsgi.

Most of the time configuring Django on Apache comes down to this line:

WSGIScriptAlias / /path/to/project/bin/django.wsgi

And django.wsgi is something like this:

#!/usr/bin/python
import djangorecipe.wsgi
application = djangorecipe.wsgi.main('project.settings', logfile='')

I was also going to recommend nginx + fastcgi, as I prefer nginx to lighttpd (it's better mantained, or at least that's been my perception the last few years). But it isn't covered by Django docs and the documentation in the nginx site is not as good. I'd stick with Apache + wsgi unless you have a good reason not to (you already have nginx or lighttpd running, or have a good reason to think that the difference in performance using fastcgi may be significant for your site). In that case here are two howtos. The gist of it is that you run a fastcgi server with Django:

python manage.py runfcgi host=127.0.0.1 port=8080 --settings=settings

And then configure nginx to send requests to it:

location / {
     # host and port to fastcgi server
     fastcgi_pass 127.0.0.1:8080;
     # (...)

Upvotes: 2

Related Questions