Take the 2-minute tour ×

I've setup my Django application on Apache+mod_wsgi. To serve the static files I'm using Nginx, as suggested on Django's project website. http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/

Apache is running on port 8081 and nginx is on port 80. Now some people have suggested that my configuration is wrong and I should reverse the roles of Apache and Nginx. I'm not sure why that should be. And if indeed my configuration is wrong, why would django website suggest the wrong method?

share|improve this question
It's safe to stick with Nginx on port 80. Care to share where you've found people saying apache is a better reverse proxy? Benchmarks are key. –  Yuji 'Tomita' Tomita Feb 3 '11 at 16:29
While I was setting up my application, I posted questions on so stackoverflow.com/questions/4868213/… and sf serverfault.com/questions/229842/apache-reverseproxy-to-nginx. And I got similar response on both pages. –  Neo Feb 3 '11 at 16:35

1 Answer 1

up vote 10 down vote accepted

The django docs you linked to do not suggest you use apache as a reverse proxy. They simply suggest you use a separate web server, so I'd say the docs are not clear on that subject -- they are not suggesting anything wrong.

My initial answer was assuming you had nginx as a reverse proxy because port 80 is the HTTP port, the one used when a browser attempts to go to a url with no port specified.

There are numerous complete guides to setting up nginx + apache via a quick google search but here is the gist for setting up nginx:

location / {
        # proxy / requests to apache running django on port 8081
        proxy_redirect     off;

location /media/ { 
        # serve static media directly from nginx
        root   /srv/anuva_project/www/;
        expires 30d;

All you need to do is remove the proxy lines from your apache configuration and add the proxy statements to your nginx.conf instead.

If you really want to serve your site from port 8081, you could potentially have nginx listen on port 8081 and have apache listen on a different port.

The point is, apache sits in some obscure port, only serving requests sent to it from nginx, while static file serving is handled by nginx.

share|improve this answer
I'm frankly confused here. Or maybe I've got the whole server concepts wrong. Since Django is running on Apache, to serve static media I have to reverse proxy through Apache to reach nginx. So I'm indeed using reverse proxy in apache configuration files. For example my main application is on: enpass.djangoserver:8081/accounts . While in the django templates, I retrieve static files from nginx. So I guess apache is in the front(and not nginx, as u said in ur answer). Or I've got my concepts upside down. –  Neo Feb 3 '11 at 16:52
Port 80 is the HTTP port, so visiting example.com would be whatever server is listening to port 80. In your case, it's nginx. Nginx would then proxy requests not to your media folders to apache on 8081 –  Yuji 'Tomita' Tomita Feb 3 '11 at 16:54
"Nginx would then proxy requests not to your media folders to apache on 8081" -- Can you elaborate. I'm a noob as far as apache/nginx are concerned. And surely, I haven't configured Nginx for any sort of proxy. –  Neo Feb 3 '11 at 16:59
Let me update the post :) You're right, I assumed port 80 is your reverse proxy because otherwise your users would have to type in a port number to visit your site. –  Yuji 'Tomita' Tomita Feb 3 '11 at 17:00
Oh, now I get it. I was reversing from apache to nginx while it should be other way around. Thanks. –  Neo Feb 3 '11 at 17:16

Your Answer


