mod_proxy and mod_vhost_alias are two very important extensions/modules for Apache web-server. When it comes to hosting multiple websites on same Web-Server using Apache or requirement to run Apache and IIS together then mod_proxy and mod_vhost_alias are key to succeed.
Here is summary of definition for both modules from Apache docs.
mod_proxy:
This module implements a proxy/gateway for Apache. It implements proxying capability for
FTP,CONNECT(for SSL),HTTP/0.9,HTTP/1.0, andHTTP/1.1. The module can be configured to connect to other proxy modules for these and other protocols.Apache's proxy features are divided into several modules in addition to
mod_proxy:mod_proxy_http,mod_proxy_ftpandmod_proxy_connect. Thus, if you want to use one or more of the particular proxy functions, loadmod_proxyand the appropriate module(s) into the server (either statically at compile-time or dynamically via theLoadModuledirective).In addition, extended features are provided by other modules. Caching is provided by
mod_cacheand related modules. The ability to contact remote servers using the SSL/TLS protocol is provided by theSSLProxy*directives ofmod_ssl. These additional modules will need to be loaded and configured to take advantage of these features.mode_vhost_alias:
This module creates dynamically configured virtual hosts, by allowing the IP address and/or the
Host:header of the HTTP request to be used as part of the pathname to determine what files to serve. This allows for easy use of a huge number of virtual hosts with similar configurations.
How to host multiple domains/sub-domains on a web-server using Apache Virtual-Hosting (mod_vhost_alias)?
This is another common requirement where we need to host multiple domains or sub-domains on a single web-server, to do if you are using Apache 2.x then just un-comment following line from httpd.conf file if it is commented.
LoadModule vhost_alias_module modules/mod_vhost_alias.so
With Apache 2.x directory structure for go to /apache/conf/extra/httpd-vhost.conf and paste following line of code:
<VirtualHost *:80>
DocumentRoot D:/www/digitss.com
ServerName digitss.com
ServerAlias www.digitss.com
ServerAlias digitss.net
ErrorLog logs/digitss.com-error.log
CustomLog logs/digitss.com-access.log common
<Directory "D:/www/digitss.com">
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
We can specify another web-root for specific virtual-host as well and it can have complete different configuration too. We can also specify as much ServerAlias as we want, all of which will point to a single server.
How to pass request from Apache to ISS or any other web-server running on another port of same/other server?
This could be a common requirement when we need to have one main domain running with Apache Server serving LAMP web-app and we want some IIS application to host on same server but we don't want user to access them by typing in www.domain.com:88 or something similar we just want it to be accessible via regular port 80. Yes, we would need mod_vhost_alias and mod_proxy both of them active to make it work. Un-comment following lines from Apache's httpd.conf file:
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so
Here is the simple set of line, placing them in /apache/conf/extra/httpd-vhost.conf file should do the magic for you:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:88/
ProxyPassReverse / http://127.0.0.1:88/
ServerName apps.digitss.com
ErrorLog logs/apps.digitss.com-error.log
CustomLog logs/apps.digitss.com-access.log common
</VirtualHost>
#or
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://anotherdomain.com:8008/
ProxyPassReverse / http://anotherdomain.com:8008/
ServerName apps.digitss.com
ErrorLog logs/apps.digitss.com-error.log
CustomLog logs/apps.digitss.com-access.log common
</VirtualHost>
For above example, apps.digitss.com will point to either local or remote proxy server running on other port and will be transparent to users.
References:
http://httpd.apache.org/docs/2.0/mod/mod_proxy.html
http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html
Please comment and let me know if mod_proxy or mod_vhost_alias has done some other magic for you.!
#1 by Andy on March 22, 2011 - 3:19 pm
Quote
Your mod_vhost_alias example is nothing more than classic virtual hosting with aliases, and will run without the vhost_alias_module. The VirtualDocumentRoot directive is required to fulfil *dynamic* virtual hosting – the intended purpose of mod_vhost_alias (despite its name). See http://httpd.apache.org/docs/2.2/mod/mod_vhost_al…