Configuration of virtual hosts on Apache

Source: Internet
Author: User

Apache supports configuring multiple virtual hosts on one server. One IP address corresponds to N domain names, and one domain name corresponds to n different IP addresses.

The following describes how to configure a virtual host on Apache.

1. First, find the Apache configuration file:

CD/usr/local/apache2/CONF/

Ii. edit the file:

Sudo Vim httpd. conf

Because the port number of the configured VM is 8080, add a line under listen 80

LIsten 8080

3. Follow the prompts in httpd. conf:

Configure the VM in the httpd-vhosts.conf under the extra directory

Sudo Vim extra/httpd-vhosts.conf 

A) First add a row under namevirtualhost *: 80.

Namevirtualhost*: 8080

B) Add the following content at the bottom of the file:

<Virtualhost *: 8080>

DocumentRoot "/home/daveyhuang/apache_test/htdocs /"

 Servername daveyhuang.com

ScriptAlias/cgi-bin/"/home/daveyhuang/apache_test/cgi-bin /"

<Directory"/Home/daveyhuang/apache_test/htdocs">

AllowOverride none

Options none

Order allow, deny

Allow from all

</Directory>

<Directory"/Home/daveyhuang/apache_test/cgi-bin/">

AllowOverride none

Options none

Order allow, deny

Allow from all

</Directory>

</Virtualhost>

Set the default document path to/home/daveyhuang/apache_test/htdocs/

The domain name is

At the same time, the access to cgi-bin on port 8080 is mapped to access to files in/home/daveyhuang/apache_test/cgi-bin.

4. Restart the apache service process

Sudo/usr/local/apache2/bin/apachectl restart

This completes the configuration.

V. Running

Modify the host file in c: \ windows \ system32 \ drivers \ etc. When the browser parses the domain name, it first searches for the IP address corresponding to the domain name in the host file. If it is not found, then go to the DNS for resolution. To make daveyhuang.com correspond to the virtual host I configured, you also need to modify the host file,

Add the following sentence to the host file:

172.25.40.134 daveyhuang.com

In this way, input daveyhuang.com: 8080 in the browser to connect to the corresponding index.html file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.