Apache 2.3 or later
With Apache 2.3 or later you can apparently do something like this (tested):
<VirtualHost *:80>
ServerName www.example.com
<If "-R '10.10.10.10'">
# The next version of the website...
Alias /favicon.ico /home/ubuntu/website-new/favicon.ico
Alias /static/ /home/ubuntu/static/
WSGIScriptAlias / /home/ubuntu/website-new/main/wsgi.py
</If>
<Else>
# The standard version (e.g. holding page).
Alias /favicon.ico /home/ubuntu/website/favicon.ico
Alias /static/ /home/ubuntu/static/
WSGIScriptAlias / /home/ubuntu/website/main/wsgi.py
</Else>
# and so on...
</VirtualHost>
Apache 2.2 or earlier
Update: This is not a good solution. See below.
You have to do a hack like this. Note the [PT]
which stands for "passthrough". Without it, an actual HTTP redirect is sent back to the client, which probably isn't what you want. The [OR]
thing (which stands for "or") shows how to match multiple addresses.
Alias /next/favicon.ico /home/ubuntu/website-new/favicon.ico
Alias /next/static/ /home/ubuntu/static/
WSGIScriptAlias /next /home/ubuntu/website-new/main/wsgi.py
Alias /favicon.ico /home/ubuntu/website/favicon.ico
Alias /static/ /home/ubuntu/static/
WSGIScriptAlias / /home/ubuntu/website/main/wsgi.py
# Rewrite for our IP.
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^80\.4\.170\.209$ [OR]
RewriteCond %{REMOTE_ADDR} ^94\.193\.52\.157$
RewriteRule ^/(.*) /next/$1 [PT]
You need to enable mod_rewrite
which you can do on Debian/Ubuntu with this command:
sudo a2enmod rewrite
Note that this method doesn't completely ban other people from accessing your test site, so you will probably want to add some security, or just choose a more obscure prefix than next
.
Update on the mod_rewrite method.
There are a couple of problems with this method. First, Django does not work with two sites in the same process like this, you need to follow the instructions in this answer.
Secondly mod_rewrite does not work with POST
requests! All POST
s are silently changed to GET
and the post data is discarded. Very frustrating! Therefore I recommend you use the...
iptables version
Simply run the servers on two different ports. This one includes the WSGI stuff to have two separate django sites.
<VirtualHost *:80>
ServerName www.example.com
Alias /favicon.ico /home/ubuntu/alpha/favicon.ico
Alias /static/ /home/ubuntu/alpha/static/
WSGIDaemonProcess alpha_wsgi user=www-data group=www-data
WSGIScriptAlias / /home/ubuntu/alpha/alpha/wsgi.py
WSGIProcessGroup alpha_wsgi
ServerAdmin info@example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:1222>
ServerName www.example.com
Alias /favicon.ico /home/ubuntu/main/favicon.ico
Alias /static/ /home/ubuntu/main/static/
WSGIDaemonProcess main_wsgi user=www-data group=www-data
WSGIScriptAlias / /home/ubuntu/main/main/wsgi.py
WSGIProcessGroup main_wsgi
ServerAdmin info@example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Then you can use this iptables
command to route requests from your ip address on port 80 to port 1222:
sudo iptables -A PREROUTING -t nat -p tcp -s your.ip.address --dport 80 -j DNAT --to-destination :1222
Change -A
to -D
to remove the rule.
Note that the docs suggest you need to add additional Listen
and NameVirtualHost
commands, but I actually found that it works without them, and adding them made it break (at least in ubuntu).