apache:基于端口創(chuàng)建虛擬主機(jī)
以創(chuàng)建虛擬主機(jī)(a,b,c)為例子
1)2.1.2禁用默認(rèn)的主機(jī)模式
[root@localhost httpd]# vim /etc/httpd/conf/httpd.conf
在主配置文件里面注釋下面這行內(nèi)容
#DocumentRoot "/var/www/html"
2)在主配置文件添加監(jiān)聽端口
找到Listen行,在原有行Listen 80行的基礎(chǔ)上, 在添加一行
Listen 8080
Listen 81
3)添加端口配置虛擬
[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:81
DocumentRoot "/var/www/c"
ServerName www.c.com
</VirtualHost>
4)創(chuàng)建新目錄
[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
[root@localhost ~]#systemctl restart httpd
注意:一定要重啟httpd!!!
最后效果:
到此這篇關(guān)于apache基于端口創(chuàng)建虛擬主機(jī)的示例的文章就介紹到這了,更多相關(guān)apache端口創(chuàng)建虛擬主機(jī)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!