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.


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;
server_name django-site.com;
location / {
include /etc/nginx/proxy.conf;
server {
listen 80;
server_name regular-site.com;
location / {
include /etc/nginx/proxy.conf;

Apache Settings /etc/apache2/sites-enabled


    ServerName django-site.com

    <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"


ServerName regular-site.com
ServerAlias regular-site.com
ServerAdmin admin@regularsite.com
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
  • I have a follow-up question though, If I only add the server{ ... } in nginx for only django-site.com it'll only proxy django-site.com and other sites will continue to run directly through apache right? – Marconi Feb 7 '11 at 9:29
  • 1
    @Marconi No. That will only happen if you specify your URL like domain.com:8085. 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
  • @Martin: I see. But I doubt the guys will let me mess around their setup. I'm not a regular employee on them, just working on this django project but thanks a lot for the help. =) – Marconi Feb 8 '11 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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