2

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?

4
  • 1
    nginx, lighttpd are pretty good alternatives.. Using apache yes I'd use mod_wsgi, hence mod_python seems pretty much deprecated Commented Jan 3, 2012 at 9:00
  • After a little search it states on the django website that mod_python will be deprecated after version 1.5 Commented Jan 3, 2012 at 9:17
  • Is there much of a performance gain / loss by using nginx over apache Commented Jan 3, 2012 at 9:18
  • Reality is that at this point it will not matter one bit what WSGI hosting solution you use. Basically anything will work. Whether one solution is better than another for your specific application will be impossible for you to tell until your site actually gets traffic and you monitor the performance of the site with real users. In other words, it is a waste of time chasing what is the theoretically best platform. You would be better off working on getting some monitoring in place so you know how well it is running once deployed. Commented Jan 3, 2012 at 22:01

2 Answers 2

2

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/

Sign up to request clarification or add additional context in comments.

2 Comments

Please rephrase your answer. "you can not use Apache" sounds a little to prescriptive for me. The OP indeed can use Apache + mod_wsgi and it'd be a reasonable setup. If you think this one is better please state the advantages, etc.
www.jeremybowers.com currently consists of a plain "Welcome to nginx!" message. Not filling me with confidence there :)
2

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;
     # (...)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.