apache:基于端口創(chuàng)建虛擬主機(jī)
以創(chuàng)建虛擬主機(jī)(a,b,c)為例子
1)2.1.2禁用默認(rèn)的主機(jī)模式
123[root@localhost httpd]# vim /etc/httpd/conf/httpd.conf在主配置文件里面注釋下面這行內(nèi)容#documentroot \”/var/www/html\”
2)在主配置文件添加監(jiān)聽端口
123找到listen行,在原有行l(wèi)isten 80行的基礎(chǔ)上, 在添加一行l(wèi)isten 8080 listen 81
3)添加端口配置虛擬
12345678910111213[root@localhost httpd]#vim /etc/httpd/conf.d/virtualhost.conf<virtualhost 192.168.87.131:80>documentroot \”/var/www/a\”servername www.a.com</virtualhost><virtualhost 192.168.87.131:8080>documentroot \”/var/www/b\”servername www.b.com</virtualhost><virtualhost 192.168.87.131:81documentroot \”/var/www/c\”servername www.c.com</virtualhost>
4)創(chuàng)建新目錄
12345[root@localhost conf.d]# cd/var/www [root@localhost www]# mkdir a b c[root@localhost www]# echo welcome to www.a.com >> ./a/index.html[root@localhost www]# echo welcome to www.b.com >> ./b/index.html[root@localhost www]# echo welcome to www.c.com >> ./c/index.html
5)重啟httpd
1[root@localhost ~]#systemctl restart httpd
注意:一定要重啟httpd!!!