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
在文件尾添加“Web服务器IP地址 tts8.tedu.cn ne.tedu.cn”内容
2) Configure the HTTPD service to achieve 2 different websites
本机访问 http://tts8.tedu.cn/ 时,网页显示 “Hello Student”本机访问 http://ne.tedu.cn/ 时,网页显示 “Hello Engineer 步骤
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/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.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.cn
PING tts8.tedu.cn (192.168.70.120) bytes of data.
Bytes from tts8.tedu.cn (192.168.70.120): icmp_seq=1 ttl=64 time=0.321 ms
Bytes from tts8.tedu.cn (192.168.70.120): icmp_seq=2 ttl=64 time=0.052 ms
^C//Press CTRL + C key combination to abort the test
.. ..
[[email protected] ~]# Ping ne.tedu.cn
PING tts8.tedu.cn (192.168.70.120) bytes of data.
Bytes from tts8.tedu.cn (192.168.70.120): icmp_seq=1 ttl=64 time=0.022 ms
Bytes from tts8.tedu.cn (192.168.70.120): icmp_seq=2 ttl=64 time=0.051 ms
^C//Press CTRL + C key combination to abort the test
.. ..
[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.html
Hello Student
Content of the second site:
[[email protected] ~]# mkdir /var/www/web2[[email protected] ~]# vim /var/www/web2/index.htmlHello Engineer 2)添加新的Web配置,支持两个虚拟Web主机,分别指向不同的网页目录
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> 作好语法检查,确保没有配置错误: [[email protected] ~]# httpd -t.. ..Syntax OK
[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 3.
When http://ne.tedu.cn/is accessed, the Web page displays "Hello Engineer", as shown in 4.
Configure a virtual Web site host