I have webserver1 behind a router currently serving all http traffic to mydomain.com. I just added webserver2, and want to redirect mydomain.com/server2 traffic to that box. To the user, the redirect should be unnoticed (i.e. the URL should just be mydomain.com/server2, 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 ^/$ http://192.168.1.102/ [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>
ServerAdmin [email protected]
ServerName www.mydomain.com
ServerAlias 127.0.0.1
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/server2/
RewriteRule ^/$ http://192.168.1.102 [P,L]
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
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 127.0.0.0/255.0.0.0 ::1/128
</Directory>
<Directory /var/www/mydomain>
Order allow,deny
Allow from all
</Directory>
...
WSGIDaemonProcess mydomain user=user group=user threads=25
WSGIProcessGroup mydomain
WSGIScriptAlias / /home/user/mydomain/apache/django.wsgi
Alias /phpmyadmin /usr/share/phpmyadmin/
</VirtualHost>
Thanks in advance.
Mod_Rewrite is more flexible than mod_proxy. Uncomment the load line for it.
Simple comparison here http://www.wellho.net/mouth/1376_Choosing-between-mod-proxy-and-mod-rewrite.html
Note that this example is case sensitive.
Use:
You may also need ProxyPassReverse as well. See Apache documentation:
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass
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.