虚拟Web主机
- 由同一台服务器提供多个不同的Web站点
- 通常以域名区分多个
需求:
1)修改 /etc/hosts 文件,临时解决DNS名称识别问题
- 在文件尾添加“Web服务器IP地址 tts8.alice.cn ne.alice.cn”内容
2)配置 httpd 服务,实现 2 个不同的网站
- 本机访问 http://tts8.alice.cn/ 时,网页显示 “Hello Student”
- 本机访问 http://ne.alice.cn/ 时,网页显示 “Hello Engineer”
配置:
以 LAMP 平台 为基础
为网站申请DNS域名
如果 暂时没有可用的域名,可临时 调整 /etc/host 文件
[root@pxesvr ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.7 tts8.alice.cn ne.alice.cn
测试访问结果
使用ping命令检测到两个域名的访问,确保可连通且对应到正确的IP地址。
[root@pxesvr ~]# ping tts8.alice.cn
PING tts8.alice.cn (192.168.10.7) 56(84) bytes of data.
64 bytes from tts8.alice.cn (192.168.10.7): icmp_seq=1 ttl=64 time=0.031 ms
64 bytes from tts8.alice.cn (192.168.10.7): icmp_seq=2 ttl=64 time=0.067 ms
64 bytes from tts8.alice.cn (192.168.10.7): icmp_seq=3 ttl=64 time=0.069 ms
^C
--- tts8.alice.cn ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.031/0.055/0.069/0.019 ms
[root@pxesvr ~]# ping ne.alice.cn
PING tts8.alice.cn (192.168.10.7) 56(84) bytes of data.
64 bytes from tts8.alice.cn (192.168.10.7): icmp_seq=1 ttl=64 time=0.029 ms
64 bytes from tts8.alice.cn (192.168.10.7): icmp_seq=2 ttl=64 time=0.075 ms
64 bytes from tts8.alice.cn (192.168.10.7): icmp_seq=3 ttl=64 time=0.043 ms
64 bytes from tts8.alice.cn (192.168.10.7): icmp_seq=6 ttl=64 time=0.050 ms
64 bytes from tts8.alice.cn (192.168.10.7): icmp_seq=7 ttl=64 time=0.070 ms
^C
--- tts8.alice.cn ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6000ms
rtt min/avg/max/mdev = 0.029/0.058/0.075/0.016 ms
配置 httpd 服务,实现 2 个不同的网站
为两个网站分别准备网页目录、测试网页index.html
第一个网站的内容:
[root@svr7 ~]# mkdir /var/www/web1
[root@svr7 ~]# vim /var/www/web1/index.html
Hello Student
第二个网站的内容:
[root@svr7 ~]# mkdir /var/www/web2
[root@svr7 ~]# vim /var/www/web2/index.html
Hello Engineer
添加新的Web配置,支持两个虚拟Web主机,分别指向不同的网页目录
<VirtualHost *:80>
ServerName tts8.alice.cn
DocumentRoot /var/www/web1
</VirtualHost>
<VirtualHost *:80>
ServerName ne.alice.cn
DocumentRoot /var/www/web2
</VirtualHost>
检查语法是否存在错误
[root@pxesvr ~]# httpd -t
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::5eb9:c07f:7440:d2c4. Set the 'ServerName' directive globally to suppress this message
Syntax OK
重启httpd服务:
[root@pxesvr ~]# systemctl restart httpd
验证:
从浏览器分别访问两个虚拟Web主机,对比页面结果
下一页:安装Discuz!论坛