Configuring the HTTPD service virtual host

Source: Internet
Author: User


Experiment Preparation:

1, prepare three site page 650) this.width=650; "Src=" https://s4.51cto.com/oss/201710/23/ 97ca07704a38c458a355afe1743fc5ee.png "title=" 2.png "alt=" 97ca07704a38c458a355afe1743fc5ee.png "/>

2. Prepare three IP addresses

650) this.width=650; "src=" Https://s2.51cto.com/oss/201710/23/a44fe3cc04dcba1bff4c438d16a8bd77.png "title=" 3.png " alt= "A44fe3cc04dcba1bff4c438d16a8bd77.png"/>

First, the implementation of IP-based virtual host

1. Modify the configuration file for the HTTPD service /etc/httpd/conf/httpd.conf

<virtualhost 192.168.35.13:80>documentroot/app/site1</virtualhost> <virtualhost 192.168.35.14:80 >documentroot/app/site2</virtualhost> <virtualhost 192.168.35.15:80>documentroot/app/site3</ Virtualhost>

2. Test connection

[[email protected] ~]# Curl 192.168.35.13/app/site1/index.html[[email protected] ~]# Curl 192.168.35.14/app/site2/ Index.html[[email protected] ~]# Curl 192.168.35.15/app/site3/index.html




Second, the implementation of virtual host based on different ports

Experimental steps:

1, modify the httpd service configuration file /etc/httpd/conf/httpd.conf

Listen 8001listen 8002listen 8003<virtualhost *:8001>documentroot/app/site1</virtualhost> < VirtualHost *:8002>documentroot/app/site2</virtualhost> <virtualhost *:8003>documentroot/app/site3 </virtualhost>


2. Test connection

[Email protected] ~]# curl192.168.35.136:8001/app/site1/index.html[[email protected] ~]# curl192.168.35.136:8002/ App/site2/index.html[[email protected] ~]# Curl 192.168.35.136:8003/app/site3/index.html

Third, implement the FQDN-based virtual host

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/23/e69e296cc58cc055dfd13e2f79dfd443.png "title=" 20171019151042.png "alt=" E69e296cc58cc055dfd13e2f79dfd443.png "/>

When the client accesses a URL, the DNS server resolves the host name to IP address access. However, for some sites that do not have a large number of visits, there may be multiple sites placed on a Web server, this time, regardless of which website address entered, DNS resolves to an IP address, in order to resolve this situation, you need to use to the virtual host.

Experimental steps:

1, analog DNS resolution vim/etc/hosts

[Email protected] app]# vim/etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.35.136 www.a.com www.b.comwww.c.com

2, modify the httpd service configuration file /etc/httpd/conf/httpd.conf

Namevirtualhost *:80<virtualhost *:80>documentroot/app/site1servername Www.a.comerrorlog logs/ A.com.errlogcustomlog logs/a.com.accesslog combined</virtualhost> <virtualhost *:80>documentroot/app/ Site2servername www.b.comerrorlog logs/b.com.errlogcustomlog Logs/b.com.accesslog combined</virtualhost> < VirtualHost *:80>documentroot/app/site3servername www.c.comerrorlog Logs/c.com.errlogcustomlog logs/ C.com.accesslog combined</virtualhost>

3. Test Connection

[[email protected] ~]# Curl Www.a.com/app/site1/index.html[[email protected] ~]# Curl www.b.com/app/site2/index.html[[ Email protected] ~]# Curl www.c.com/app/site3/index.html

Experimental summary: Based on IP address implementation of virtual host, how many URLs will require the number of IP addresses, which creates a waste of resources, but also increase the cost, and based on the port in the access to enter the port number, and the general user can remember the port number, so access is more troublesome, So the current mainstream is the local FQDN implementation of the virtual host.

Configuring the HTTPD service virtual host

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.