forward snippets

Configuring Apache to be a forward proxy

Tagged apache, forward, proxy, rewrite, forward proxy  Languages apacheconf

First enable the proxy and proxy_http modules:

sudo a2enmod proxy
sudo a2enmod proxy_http

Then use this configuration to make Apache act as an HTTP proxy:

<VirtualHost *:8080>
# Enable forward proxy
ProxyRequests On
# Add "Via" header
ProxyVia On
#ProxyRemote * http://...:8080 Uncomment to route requests through another proxy

<Proxy *>
    Order deny,allow
      Deny from all
  # Allow access only from local network
  Allow from 192.168.1
# Enable caching proxy
CacheRoot "/tmp"
CacheMaxExpire 24
CacheLastModifiedFactor 0.1
CacheDefaultExpire 1

ServerName my-proxy

ErrorLog "/var/log/apache2/proxy-error.log"
CustomLog "/var/log/apache2/proxy-access.log" common

Also read this.


You can use mod_rewrite to rewrite requests. To rewrite root (/) to /temporary_outage you could use the following rewrite:

RewriteCond %{HTTP_HOST} ^(www\.)?xxx\.com 
RewriteRule /$ http://%{HTTP_HOST}/temporary_outage/ [P,L]