Consultor Eletrônico



Kbase P48804: How to setup Virtual Host in Apache with a separate cgi-bin, ScriptAlias, directory in Apache?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   9/15/2008
Status: Verified

GOAL:

How to setup Virtual Host in Apache with a separate cgi-bin, ScriptAlias, directory in Apache?

FACT(s) (Environment):

All Supported Operating Systems
Apache

FIX:

This article explains how to configure Virtual Host in Apache web server to host three different web sites on the web server with two different IP address.

Usually, the Apache configuration file(httpd.conf) resides on the following directory structure unless it was installed in a separate directory:

/usr/local/Apache/conf, or /usr/local/httpd/conf

Let's consider the two different domains to host Apache web server:

myapache.com on 192.168.0.1
myapache1.com on 192.168.0.2

In any OS, you can use any of your favorite text editor to add or modify the httpd.conf file.

There are two methods of setting up IP address for Apache server to listen for connection:

1. using BindAddress directive (is deprecated and will be eliminated in Apache 2.0)

BindAddress directive can be setup to listen to all the IP address or only one IP address in the server machine to listen to using only one port, i.e., port 80.

To configure all IP address use the following:

BindAddress *

To configure only one IP address use the following:

BindAddress 198.168.0.1

Since this article is about settings of the multiple Virtual Host, the later example can be disregarded but this is mentioned so you know.

2. Listen Directive

This can be used instead of BindAddress directive to tell the server to accept incoming requests (to listen) on the specified port or address-and-port combination.

If the first format is used, with a port number only, the server listens on the given port on all interfaces marked as up, instead of the port given by the Port directive. If an IP address is given as well as a port, the server will listen on the given port and interface.

Multiple Listen directives may be used to specify a number of addresses and ports to listen to. The server will respond to requests from any of the listed addresses and ports.

For example, to make the server accept connections on both port 80 and port 8000, use:

Listen 80
Listen 8000

To make the server accept connections on two specified interfaces and port numbers, use:

Listen 192.168.0.1:80
Listen 192.168.0.2:8000

In this case you can leave port 80 as a listening port for all the IP.

Next you need to configure name-based virtual hosting. This feature is available in Apache 1.3 or later. This setting tells Apache that you are creating name-based virtual hosts using those two IP addresses. Apache looks at the incoming header, sees the name of the web site being requested, and answers appropriately.

Find the "NameVirtualHost" section in the httpd.conf file and add the following:

NameVirtualHost 192.168.0.1
NameVirtualHost 192.168.0.2

The following goes under the virtual host section:

<VirtualHost 192.168.0.1>
ServerAdmin johndow@myapache.dom
ServerName www.myapache.com
ServerAlias www.myapache.com web.myapache.com myapache.com
DocumentRoot /home/johndow/web/myapache
ScriptAlias /cgi-bin/ "/home/johndow/web/myapache/cgi-bin/"
ErrorLog /home/johndow/web/myapache/logs/error_log
TransferLog /home/johndow/web/myapache/logs/access_log
</VirtualHost>

<VirtualHost 192.168.0.2>
ServerAdmin johndow@myapache1.com
ServerName www.myapache1.com
ServerAlias www.myapache1.com web.myapache1.com myapache1.com
DocumentRoot /home/johndow/web/myapache1
ScriptAlias /cgi-bin/ "/home/johndow/web/myapache1/cgi-bin/"
ErrorLog /home/johndow/web/myapache1/logs/error_log
TransferLog /home/johndow/web/myapache1/logs/access_log
</VirtualHost>