- 更改配置文件,添加三个不同端口的虚拟主机
<directory /www>
allowoverride none
require all granted
</directory>
<virtualhost 192.168.209.136:80>
documentroot /www
servername 192.168.209.136
</virtualhost>
<virtualhost 192.168.209.138:80>
documentroot /www/138
servername 192.168.209.138
</virtualhost>
<virtualhost 192.168.209.139:80>
documentroot /www/139
servername 192.168.209.139
</virtualhost>
<virtualhost 192.168.209.136:9090>
documentroot /www/9090
servername 192.168.209.136
</virtualhost>
<virtualhost 192.168.209.136:9091>
documentroot /www/9091
servername 192.168.209.136
</virtualhost>
<virtualhost 192.168.209.136:9092>
documentroot /www/9092
servername 192.168.209.136
</virtualhost>
- 创建/
www/9090、/www/9091/、www/9092
三个文件夹
[root@localhost conf.d]# mkdir /www/909{0..2}
- 往/
www/9090、/www/9091/、www/9092
三个文件里的index.html
文件写入内容
[root@localhost conf.d]# echo welcome to 9090 > /www/9090/index.html
[root@localhost conf.d]# echo welcome to 9091 > /www/9091/index.html
[root@localhost conf.d]# echo welcome to 9092 > /www/9092/index.html
- 重启httpd服务
[root@localhost conf.d]# systemctl restart httpd
- 查看监听端口
[root@localhost conf.d]# netstat -lntup | grep httpd
tcp6 0 0 :::80 :::* LISTEN 17900/httpd
此时没有我们配置的9090、9091、9092三个端口,所以我们需要继续在vhost.conf配置文件中添加监听端口
- 再重启服务,再查看监听
[root@localhost conf.d]# systemctl restart httpd
[root@localhost conf.d]# netstat -lntup | grep httpd
tcp6 0 0 :::9092 :::* LISTEN 18143/httpd
tcp6 0 0 :::9090 :::* LISTEN 18143/httpd
tcp6 0 0 :::9091 :::* LISTEN 18143/httpd
tcp6 0 0 :::80 :::* LISTEN 18143/httpd
- 浏览器中访问
此实验基于上一篇实验的基础之上完成