The following example illustrates the use of name-based virtual hosts. We define two virtual hosts, www.example.com and www.example.org, which will reverse-proxy dynamic requests to ports 8001 and 8002 on the backend mod_perl-enabled server.
Listen 192.168.1.2:80 NameVirtualHost 192.168.1.2:80
Replace 192.168.1.2 with your server's public IP address.
LogFormat "%v %h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\""
The log format used is the Common Log Format prefixed with %v, a token representing the name of the virtual host. Using a combined log common to all virtual hosts uses fewer system resources. The log file can later be split into seperate files according to the prefix, using splitlog or an equivalent program.
The following are global options for mod_rewrite shared by all virtual hosts:
RewriteLogLevel 0 RewriteRule \.(gif|jpg|png|txt|html)$ - [last]
This turns off the mod_rewrite module's logging feature and makes sure that the frontend server will handle files with the extensions .gif, .jpg, .png, .txt, and .html internally.
If your server is configured to run traditional CGI scripts (under mod_cgi) as well as mod_perl CGI programs, it would be beneficial to configure the frontend server to run the traditional CGI scripts directly. This can be done by altering the (gif|jpg|png|txt|html) rewrite rule to add cgi if all your mod_cgi scripts have the .cgi extension, or by adding a new rule to handle all /cgi-bin/* locations internally.
The virtual hosts setup is straightforward:
##### www.example.com <VirtualHost 192.168.1.2:80> ServerName www.example.com ServerAdmin webmaster@example.com DocumentRoot /home/httpd_docs/htdocs/www.example.com RewriteEngine on RewriteOptions 'inherit' RewriteRule ^/(perl/.*)$ http://127.0.0.1:8001/$1 [P,L] ProxyPassReverse / http://www.example.com/ </VirtualHost> ##### www.example.org <VirtualHost 192.168.1.2:80> ServerName www.example.org ServerAdmin webmaster@example.org DocumentRoot /home/httpd_docs/htdocs/www.example.org RewriteEngine on RewriteOptions 'inherit' RewriteRule ^/(perl/.*)$ http://127.0.0.1:8002/$1 [P,L] ProxyPassReverse / http://www.example.org/ </VirtualHost>
The two virtual hosts' setups differ in the DocumentRoot and ProxyPassReversesettings and in the backend ports to which they rewrite.
 
Continue to: