SUPPORT THE SITE WITH A CLICK

Subscribe Rss:

SUPPORT THE SITE WITH A CLICK

Wednesday, April 22, 2009

Apache configuration for single application serving requests from mulitple domains


#
# Proxy Server directives. Uncomment the following lines to
# enable the proxy server:
#
<IfModule mod_proxy.c>
ProxyRequests Off

<Proxy *>
Order deny,allow
Deny from all
Allow from all
</Proxy>

#ProxyPass / http://127.0.0.1:8000/dl
#ProxyPassReverse / http://127.0.0.1:8000/dl
#ProxyPreserveHost On


</IfModule>
# End of proxy directives.

Listen 8080
<VirtualHost *:8080>
<Location />
SetHandler balancer-manager
Deny from all
Allow from localhost
</Location>
</VirtualHost>

<Proxy balancer://mongrel_cluster>
BalancerMember http://127.0.0.1:7000
BalancerMember http://127.0.0.1:7001
BalancerMember http://127.0.0.1:7002
</Proxy>

<VirtualHost *:80>
Include /etc/apache2/sites-enabled/1.conf

ServerName example1.com
LogFormat "%h %l %u %t \"%r\" %>s %b" common
ErrorLog /home/logs/error_log
CustomLog /home/logs/access_log combined
</VirtualHost>

<VirtualHost *:80>
Include /etc/apache2/sites-enabled/2.conf

ServerName example2.com
LogFormat "%h %l %u %t \"%r\" %>s %b" common
ErrorLog /home/logs/error_log
CustomLog /home/logs/access_log combined
</VirtualHost>
<VirtualHost *:80>
Include /etc/apache2/sites-enabled/3.conf

ServerName example3.com
LogFormat "%h %l %u %t \"%r\" %>s %b" common
ErrorLog /home/logs/error_log
CustomLog /home/logs/access_log combined
</VirtualHost>
<VirtualHost *:80>
Include /etc/apache2/sites-enabled/4.conf

ServerName example4.com
LogFormat "%h %l %u %t \"%r\" %>s %b" common
ErrorLog /home/logs/error_log
CustomLog /home/logs/access_log combined
</VirtualHost>
<VirtualHost *:80>

Configuration file of virtual hosts

ServerName example1.com
ServerAlias example1.com
DocumentRoot /home/Mypace/folder/public
<Directory "/home/Mypace/folder/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<IfModule mod_proxy.c>
# For proxy
ProxyRequests Off

<Proxy balancer://mongrel_cluster>
BalancerMember http://127.0.0.1:7000
BalancerMember http://127.0.0.1:7001
</Proxy>

<Proxy *>
Order deny,allow
Deny from all
Allow from all
</Proxy>


# Enable/disable the handling of HTTP/1.1 "Via:" headers.
# ("Full" adds the server version; "Block" removes all outgoing Via: headers)
# Set to one of: Off | On | Full | Block

ProxyVia On

</IfModule>
RewriteEngine On

# Check for maintenance file and redirect all requests
# ( this is for use with Capistrano's disable_web task )
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]

# Rewrite index to check for static
RewriteRule ^/$ /index.html [QSA]

# Rewrite to check for Rails cached page
RewriteRule ^([^.]+)$ $1.html [QSA]

# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]


Place the two conf files inside your /etc/apache2/sites-enabled.
Finally in your apache2.conf(/etc/apache2) include the first configuration file Include /etc/apache2/sites-enabled/Istconf at the end of the file.

Note if you find any errors "_default_ VirtualHost overlap on port 80, the first has precedence" then refer here