Skip to content

Instantly share code, notes, and snippets.

@tuxfight3r
Created November 28, 2014 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuxfight3r/7f313cffcebae078d362 to your computer and use it in GitHub Desktop.
Save tuxfight3r/7f313cffcebae078d362 to your computer and use it in GitHub Desktop.
apache mod_proxy ssl vhost with location based access
#Sample apache mod_proxy ssl vhost with location based access
<VirtualHost *:443 *:60443>
ServerName www.nerdplanet.co.uk
ServerAlias nerdplanet.co.uk
DocumentRoot /var/www/vhosts/nerdplanet.co.uk/
#LogLevel debug
CustomLog /var/log/httpd/nerdplanet.co.uk_access_log combined
ErrorLog /var/log/httpd/nerdplanet.co.uk_error_log
SSLEngine on
SSLCertificateFile /etc/httpd/conf/ssl/nerdplanet.co.uk/nerdplanet.crt
SSLCertificateKeyFile /etc/httpd/conf/ssl/nerdplanet.co.uk/nerdplanet.key
SSLCertificateChainFile /etc/httpd/conf/ssl/nerdplanet.co.uk/intermediate_CA.cert
#redirect the root context for the site
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.nerdplanet.co.uk$ [NC]
RewriteRule ^(.*)$ https://www.nerdplanet.co.uk$1 [R=301]
#Redirect for / location
RewriteRule ^/$ /web/data/home [R]
#Redirect for /DEV location
RewriteRule ^/DEV$ /web/dev/login [R]
#Redirect for /TEST location
RewriteRule ^/TEST$ /TEST/ [R]
#Redirect for /stage location
RewriteRule ^/stage/$ /stage [R]
RewriteRule ^/stage$ /data/portal/login.html [R]
ProxyPreserveHost On
ProxyRequests Off
#Turn on the below parameter to serve custom maintenance page
#ProxyErrorOverride On
ProxyTimeout 500
## Access to the root context ##
<Location />
Order allow,deny
#Deny from all
Allow from all
</Location>
## Access to the dev portal ###
<Location /web/dev/login>
Order allow,deny
#Deny from all
#Allow from all
#Access from devs
Allow from 10.1.1.x
</Location>
<Location /TEST>
Order allow,deny
#Deny from all
#Allow from all
#Access from devs
Allow from 10.2.2.x
</Location>
## Access to the stage area ##
<Location /stage>
Order allow,deny
#Deny from all
#Allow from all
#Access from devs
Allow from 10.1.1.x
</Location>
#Allow Error Document Acess to everyone for custom 404 page
#As the rule above / denies everyone
<Location /error-documents>
Order allow,deny
Allow from all
</Location>
ProxyPass /error-documents !
ErrorDocument 503 /error-documents/error/error-503.html
ErrorDocument 403 /error-documents/error/error-403.html
Alias /error-documents /var/www/nerdplanet.co.uk
#/TEST goes here to a different host
ProxyPass /TEST http://10.1.1.10:80/TEST
ProxyPassReverse /TEST http://10.1.1.10:80/TEST
#stage goes here to a different host
ProxyPass /stage http://10.1.1.10:80/
ProxyPassReverse /stage http://10.1.1.10:80/
# / and /dev goes here to the same host but different location
ProxyPass / http://10.1.1.34:80/
ProxyPassReverse / https://www.nerdplanet.co.uk/
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment