新聞中心
一、 相同IP地址,不同端口號

成都創(chuàng)新互聯(lián)公司是一家專業(yè)提供新野企業(yè)網(wǎng)站建設(shè),專注與網(wǎng)站設(shè)計制作、網(wǎng)站制作、H5場景定制、小程序制作等業(yè)務(wù)。10年已為新野眾多企業(yè)、政府機構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)絡(luò)公司優(yōu)惠進行中。
虛擬主機1:主機IP地址為172.16.30.20,端口號為80(默認端口),DocumentRoot是/var/www/vhost1,在DocumentRoot目錄下創(chuàng)建虛擬主機站點主頁文件。
[root@rhel7 ~]# cd /var/www/ [root@rhel7 www]# mkdir vhost1 [root@rhel7 www]# cd vhost1/ [root@rhel7 vhost1]# vim index.html [root@rhel7 vhost1]# cat index.html this is the vhost1
虛擬主機2:主機IP地址為172.16.30.20,端口號為8080,DocumentRoot是/var/www/vhost2,在DocumentRoot目錄下創(chuàng)建虛擬主機站點主頁文件。
[root@rhel7 ~]# cd /var/www/ [root@rhel7 www]# mkdir vhost2 [root@rhel7 www]# cd vhost2/ [root@rhel7 vhost2]# vim index.html [root@rhel7 vhost2]# [root@rhel7 vhost2]# cat index.html this is the vhost2
編輯虛擬機主機配置文件httpd-vhosts.conf
[root@rhel7 ~]# vim /etc/httpd/conf.d/httpd-vhosts.confDocumentRoot "/var/www/vhost1" Listen 8080DocumentRoot "/var/www/vhost2" [root@rhel7 ~]# systemctl restart httpd [root@rhel7 ~]# firewall-cmd --add-port=8080/tcp --permanent success [root@rhel7 ~]# firewall-cmd --reload success
訪問測試:
二、 不同IP地址,相同端口號
虛擬主機1:主機IP地址為172.16.30.20,端口號為80(默認端口),DocumentRoot是/var/www/vhost1,在DocumentRoot目錄下創(chuàng)建虛擬主機站點主頁文件。
虛擬主機2:主機IP地址為172.16.30.200,端口號為80(默認端口),DocumentRoot是/var/www/vhost2,在DocumentRoot目錄下創(chuàng)建虛擬主機站點主頁文件。
[root@rhel7 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=Ethernet BOOTPROTO=none DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens33 UUID=bde41fa3-f559-4de2-ba9a-857fed211aac DEVICE=ens33 ONBOOT=yes DNS1=127.0.0.1 ZONE=public IPADDR=172.16.30.10 PREFIX=24 IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPADDR1=172.16.30.100 PREFIX1=24
[root@rhel7 ~]# vim /etc/httpd/conf.d/httpd-vhosts.confDocumentRoot "/var/www/vhost1" DocumentRoot "/var/www/vhost2" [root@rhel7 ~]# systemctl restart httpd
訪問測試:
三、 相同IP地址,相同端口號,不同F(xiàn)QDN
虛擬主機1:主機IP地址為172.16.30.20,端口號為80(默認端口),F(xiàn)QDN為vhost1.example.com,DocumentRoot是/var/www/vhost1,在DocumentRoot目錄下創(chuàng)建虛擬主機站點主頁文件。
虛擬主機2:主機IP地址為172.16.30.20,端口號為80(默認端口),F(xiàn)QDN為vhost2.example.com,DocumentRoot/var/www/vhost2,在DocumentRoot目錄下創(chuàng)建虛擬主機站點主頁文件。
[root@rhel7 ~]# vim /etc/httpd/conf.d/httpd-vhosts.confDocumentRoot "/var/www/vhost1" ServerName vhost1.example.com DocumentRoot "/var/www/vhost2" ServerName vhost2.example.com
注意:DNS服務(wù)器中需要添加對應(yīng)的解析內(nèi)容。
訪問測試:
記得每次修改完配置文件后需要重啟服務(wù)。
本篇文章到此結(jié)束,如果您有相關(guān)技術(shù)方面疑問可以聯(lián)系我們技術(shù)人員遠程解決,感謝大家支持本站!
創(chuàng)新互聯(lián)【028-86922220】值得信賴的成都網(wǎng)站建設(shè)公司。多年持續(xù)為眾多企業(yè)提供成都網(wǎng)站建設(shè),成都品牌網(wǎng)站設(shè)計,成都高端網(wǎng)站制作開發(fā),SEO優(yōu)化排名推廣服務(wù),全網(wǎng)營銷讓企業(yè)網(wǎng)站產(chǎn)生價值。
本文標(biāo)題:linux7下虛擬主機的三種實現(xiàn)方式
網(wǎng)站鏈接:http://m.5511xx.com/article/cossped.html


咨詢
建站咨詢
