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 webserver1 behind a router currently serving all http traffic to I just added webserver2, and want to redirect traffic to that box. To the user, the redirect should be unnoticed (i.e. the URL should just be, and the redirection happens behind the scenes). How do I set this up in the apache configuration of webserver1 (I'm assuming webserver2's config needs to do nothing special)?

I've tried the advice given here, using mod_rewrite, but it didn't seem to do the trick:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/server2/
RewriteRule ^/$ [P,L]

In case it is relevant, webserver1 is hosting a django app using mod_wsgi, with a few other apps that get redirected away. Here is the virtualhost conf:

<VirtualHost *:80>

    RewriteEngine on
        RewriteCond %{REQUEST_URI} ^/server2/
        RewriteRule ^/$ [P,L]

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from ::1/128

    <Directory /var/www/mydomain>
    Order allow,deny
    Allow from all


    WSGIDaemonProcess mydomain user=user group=user threads=25
    WSGIProcessGroup mydomain

    WSGIScriptAlias / /home/user/mydomain/apache/django.wsgi
    Alias /phpmyadmin /usr/share/phpmyadmin/


Thanks in advance.

share|improve this question
up vote 2 down vote accepted

Mod_Rewrite is more flexible than mod_proxy. Uncomment the load line for it.

Simple comparison here

<VirtualHost *:80>

RewriteEngine on

# just in case (don't want to accidentally expose all the internal servers) !
ProxyRequests off

# define a log file
RewriteLog /var/log/apache/server2.rewrite.log
RewriteLogLevel 1

# add the tailing / if not there
RewriteRule     ^/server2$  [R] [L]

# proxy the request to internal url
RewriteRule     ^/server2/(.*)$1 [P]

Note that this example is case sensitive.

share|improve this answer


ProxyPass /server2

You may also need ProxyPassReverse as well. See Apache documentation:

Note that backend mod_wsgi MUST mount application at same sub URL as it is appearing and being proxied as on front end.

Also be aware that may require configuration on back end to fiddle what host/port it appears back end application is running on so URL reconstruction in back end works properly when used. So research that if you find it is an issue.

share|improve this answer
I am getting a 403 forbidden error and this is in webserver1's apache error log: [Sun Sep 05 18:21:13 2010] [error] [client] client denied by server configuration: proxy: Do I need mod_proxy on webserver2? Also, I'm not clear on what you meant by the mounting issue with mod_wsgi. The django app on webserver1 is mounted at /, but it is served at – NP01 Sep 5 '10 at 12:53
Would have no idea why you get 403 as you haven't supplied any details about front end configuration. As to Django application mounting, you will need for first argument to WSGIScriptAlias to be /server2. ie., match what sub URL it appears as on front end. If you don't do this, you will need to use WSGI middleware wrapper to fiddle SCRIPT_NAME to be /server2. Don't do this and you will find that redirects issues from Django application will be wrong as will be missing /server2 in the redirect URL. – Graham Dumpleton Sep 5 '10 at 23:29

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.