Skip to content

Instantly share code, notes, and snippets.

@abhishekkr
Created January 13, 2013 21:59
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 abhishekkr/4526414 to your computer and use it in GitHub Desktop.
Save abhishekkr/4526414 to your computer and use it in GitHub Desktop.
Apache HTTPD VirtualHost ~ story of default route opted
# Multiple VirtualHosts Entry can be made to handle different internal servers serving via single external node
# Since it picks up first VirtualHost as default route... all unhandled requests served by first VirtualHost
NameVirtualHost *:80
ServerName servernode
<VirtualHost *:80>
ServerName www.about.server.node
ServerAlias about.server.node
DocumentRoot /var/www/html/about
</VirtualHost>
<VirtualHost *:80>
ServerName www.blog.server.node
ServerAlias blog.server.node
<Location />
ProxyPass http://www.server01.node/blog
ProxyPassReverse http://www.server01.node/blog
ProxyPassReverseCookiePath /blog /
</Location>
</VirtualHost>
<VirtualHost *:80>
ServerName www.projects.server.node
ServerAlias projects.server.node
<Location />
ProxyPass http://www.server02.node/projects
ProxyPassReverse http://www.server02.node/projects
ProxyPassReverseCookiePath /projects /
</Location>
</VirtualHost>
# If you just get left with one VirtualHost... all requests get left up to be served by it
NameVirtualHost *:80
ServerName servernode
<VirtualHost *:80>
ServerName www.projects.server.node
ServerAlias projects.server.node
<Location />
ProxyPass http://www.server02.node/projects
ProxyPassReverse http://www.server02.node/projects
ProxyPassReverseCookiePath /projects /
</Location>
</VirtualHost>
# Since it picks up first VirtualHost as default route... something like this could be made to work
# explicitly providing a _default_:80 to spare Server the ambiguity
NameVirtualHost *:80
ServerName servernode
<VirtualHost _default_:80>
DocumentRoot /var/www/html/404
</VirtualHost>
<VirtualHost *:80>
ServerName www.about.server.node
ServerAlias about.server.node
DocumentRoot /var/www/html/about
</VirtualHost>
<VirtualHost *:80>
ServerName www.blog.server.node
ServerAlias blog.server.node
<Location />
ProxyPass http://www.server01.node/blog
ProxyPassReverse http://www.server01.node/blog
ProxyPassReverseCookiePath /blog /
</Location>
</VirtualHost>
<VirtualHost *:80>
ServerName www.projects.server.node
ServerAlias projects.server.node
<Location />
ProxyPass http://www.server02.node/projects
ProxyPassReverse http://www.server02.node/projects
ProxyPassReverseCookiePath /projects /
</Location>
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment