Apache Configure virtual host three ways, Apache virtual host _php Tutorial

Source: Internet
Author: User

Apache Configure virtual host three ways, Apache virtual host


One, IP-based

1. Assume that the server has an IP address of 192.168.1.10, use Ifconfig to bind 3 IPs on the same network interface eth0:

[Root@localhost root]# ifconfig eth0:1 192.168.1.11
[Root@localhost root]# ifconfig eth0:2 192.168.1.12
[Root@localhost root]# ifconfig eth0:3 192.168.1.13

2. Modify the Hosts file to add three domain names to each:

192.168.1.11 www.test1.com
192.168.1.12 www.test2.com
192.168.1.13 www.test3.com

3. Set up the root directory of Web pages, such as Test1, Test2, test3 folders in the/www directory, which store 1.html, 2.html, 3.html respectively

/www/test1/1.html
/www/test2/2.html
/www/test3/3.html

4. Include the additional configuration file httpd-vhosts.conf in httpd.conf, and then write the following configuration in httpd-vhosts.conf:


ServerName www.test1.com
documentroot/www/test1/
  
Options Indexes FollowSymLinks
AllowOverride None
Order Allow,deny
Allow from all
 



ServerName www.test1.com
documentroot/www/test2/
  
Options Indexes FollowSymLinks
AllowOverride None
Order Allow,deny
Allow from all
 



ServerName www.test1.com
documentroot/www/test3/
  
Options Indexes FollowSymLinks
AllowOverride None
Order Allow,deny
Allow from all
 

5. You are done, test each virtual host, Access www.test1.com, www.test2.com, www.test3.com, respectively

Second, based on the host name

1. Set the domain name map to the same IP, modify the hosts:

192.168.1.10 www.test1.com
192.168.1.10 www.test2.com
192.168.1.10 www.test3.com

2. As above, establish the root directory of the Web page hosting the virtual host

/www/test1/1.html
/www/test2/2.html
/www/test3/3.html

3. Include the additional configuration file httpd-vhosts.conf in httpd.conf, and then write the following configuration in httpd-vhosts.conf:

In order to use a domain-based virtual host, you must specify the server IP address (and possibly the port) to allow the host to accept the request. Can be configured with the Namevirtualhost directive. If all IP addresses on the server are used, you can use * as Namevirtualhost parameters. Specifying an IP address in the NAMEVIRTUALHOST directive does not cause the server to automatically listen for that IP address. The IP address set here must correspond to a network interface on the server.

The next step is to set the configuration block for each virtual host you set up , with the same parameters as the Namevirtualhost directive. in each definition block, there is at least one servername instruction to specify which host and a documentroot instruction to indicate where the contents of this host exist in the filesystem.

If you add a virtual host to an existing Web server, you must also build a definition block for existing hosts . The contents of servername and DocumentRoot should be consistent with the global, and should be placed at the front of the configuration file, playing the role of the default host.

Namevirtualhost *:80

ServerName *

documentroot/www/

ServerName www.test1.com

documentroot/www/test1/

  

Options Indexes FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

  

ServerName www.test2.com

documentroot/www/test2/

  

Options Indexes FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

  

ServerName www.test3.com

documentroot/www/test3/

  

Options Indexes FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

  

4. You are done, test each virtual host, Access www.test1.com, www.test2.com, www.test3.com, respectively

Third, Port-based

1. Modify the configuration file

The original

Listen 80
Switch
Listen 80
Listen 8080


2. Change the virtual host settings:


documentroot/var/www/test1/
ServerName www.test1.com



Documentroot/var/www/test2
ServerName www.test2.com

http://www.bkjia.com/PHPjc/1037989.html www.bkjia.com true http://www.bkjia.com/PHPjc/1037989.html techarticle Apache configuration Virtual host three ways, Apache virtual host one, based on IP 1. Assume that the server has an IP address of 192.168.1.10, using ifconfig on the same network interface eth0 bound 3 I ...

  • 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.