Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an existing apache serving a couple of sites.

Now I have a new django site that's ajax intensive and so I'm planning to run it on apache's mod_wsgi but I'll use nginx as a reverse proxy.

Is it possible to have nginx be a reverse proxy to this new django site while make apache serve the other sites directly without using nginx?

Also if you can give me a rough setup on how I might do it if its possible.

share|improve this question
up vote 2 down vote accepted

The way I solved this problem is to have nginx reverse proxy all of the sites, but have them go to different apache virtual hosts listening on different ports.

nginx (in /etc/nginx)


proxy_redirect off; 
proxy_set_header Host $host; 
proxy_set_header X-Real-IP $remote_addr; 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
client_max_body_size 10m; 
client_body_buffer_size 128k; 
proxy_connect_timeout 90; 
proxy_send_timeout 90; 
proxy_read_timeout 90; 
proxy_buffer_size 4k; proxy_buffers 4 32k; 
proxy_busy_buffers_size 64k; 
proxy_temp_file_write_size 64k;


server {
listen 80;
location / {
include /etc/nginx/proxy.conf;
server {
listen 80;
location / {
include /etc/nginx/proxy.conf;

Apache Settings /etc/apache2/sites-enabled



    <Location "/">
       SetHandler python-program
       PythonHandler django.core.handlers.modpython
       SetEnv DJANGO_SETTINGS_MODULE settings
       PythonOption django.root
       PythonDebug On
       PythonPath "['/django/django-site'] + sys.path"


DocumentRoot /var/www/regular-site/

In /etc/apache2/apache2.conf

# Include ports listing
Include /etc/apache2/ports.conf

ports.conf must list every port /etc/apache2/ports.conf

#Listen 80
#disabled for nginx
Listen 8085
Listen 8086

<IfModule mod_ssl.c>
    Listen 443
share|improve this answer
awesome! thanks. – Marconi Feb 7 '11 at 8:46
I have a follow-up question though, If I only add the server{ ... } in nginx for only it'll only proxy and other sites will continue to run directly through apache right? – Marconi Feb 7 '11 at 9:29
@Marconi No. That will only happen if you specify your URL like The default port for a web browser to use is port 80, which is what you have Nginx listen on so all traffic has to pass through this. (Unless you use multiple IPs, but that's just making things complicated) – Martin Fjordvald Feb 7 '11 at 9:41
@Martin: Does that mean I need to create an equivalent server{...} in nginx and matching virtualhost in apache for each existing sites that apache used to serve directly? – Marconi Feb 8 '11 at 6:01
@Marconi: Ideally yeah, though if you can use the default flag of the Listen directive to create a server block which will catch all requests without a better matching server block. – Martin Fjordvald Feb 8 '11 at 7:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.