Linux Configuration virtual Web site host

Source: Internet
Author: User

1.1 Questions
This example requires the results of case 1 to be based on the HTTPD Web server to implement virtual host support, complete the following tasks:

1) Modify the/etc/hosts file to temporarily resolve the DNS name recognition problem

Add "Web server IP address tts8.tedu.cn ne.tedu.cn" content at the end of the file
2) Configure the HTTPD service to achieve 2 different websites

When the machine accesses http://tts8.tedu.cn/, the webpage displays "Hello Student"
When the machine accesses http://ne.tedu.cn/, the webpage displays "Hello Engineer"
1.2 Steps
The implementation of this case needs to follow the steps below.

Step One: Modify the/etc/hosts file to temporarily resolve the DNS name recognition problem

1) Add host mapping record, point to the normal IP address of the virtual machine (e.g. 192.168.70.120)

Add "Web server IP address tts8.tedu.cn ne.tedu.cn" content at the end of the file.

[[email protected] ~]#  vim  /etc/hosts127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4::1         localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.70.120  tts8.tedu.cn  ne.tedu.cn

2) test Access results

Use the ping command to detect access to two domain names, making sure they are reachable and correspond to the correct IP address.

[[email protected] ~]# ping  tts8.tedu.cnPING tts8.tedu.cn (192.168.70.120) 56(84) bytes of data.64 bytes from tts8.tedu.cn (192.168.70.120): icmp_seq=1 ttl=64 time=0.321 ms64 bytes from tts8.tedu.cn (192.168.70.120): icmp_seq=2 ttl=64 time=0.052 ms^C                                                  //按Ctrl+c组合键中止测试.. ..[[email protected] ~]# ping  ne.tedu.cnPING tts8.tedu.cn (192.168.70.120) 56(84) bytes of data.64 bytes from tts8.tedu.cn (192.168.70.120): icmp_seq=1 ttl=64 time=0.022 ms64 bytes from tts8.tedu.cn (192.168.70.120): icmp_seq=2 ttl=64 time=0.051 ms^C                                                  //按Ctrl+c组合键中止测试.. ..[[email protected] ~]#

Step Two: Configure the HTTPD service to achieve 2 different websites

1) Prepare a web directory for two websites, test the Web page index.html

Content of the first site:

[[email protected] ~]# mkdir  /var/www/web1[[email protected] ~]# vim  /var/www/web1/index.htmlHello  Student

Content of the second site:

[[email protected] ~]# mkdir  /var/www/web2[[email protected] ~]# vim  /var/www/web2/index.htmlHello  Engineer

2) Add a new Web configuration, support two virtual web hosts, point to different web directories

New Virtual Host Configuration:

[[email protected] ~]# vim  /etc/httpd/conf.d/vhosts.conf <VirtualHost  *:80>    ServerName  tts8.tedu.cn    DocumentRoot  /var/www/web1</VirtualHost><VirtualHost  *:80>    ServerName  ne.tedu.cn    DocumentRoot  /var/www/web2</VirtualHost>

Do a good grammar check to make sure there are no configuration errors:

[[email protected] ~]# httpd  -t.. ..Syntax OK

Restart the HTTPD service:

[[email protected] ~]# systemctl  restart  httpd

3) Access two virtual web hosts from the browser and compare page results

When http://tts8.tedu.cn/is accessed, the Web page displays "Hello Student", as shown in 1.

When http://ne.tedu.cn/is accessed, the Web page displays "Hello Engineer", as shown in 2.

Linux Configuration virtual Web site 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.