linux7下虛擬主機的三種實現(xiàn)方式
一、 相同IP地址,不同端口號
虛擬主機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.conf <VirtualHost 172.16.30.10:80> DocumentRoot "/var/www/vhost1" </VirtualHost> Listen 8080 <VirtualHost 172.16.30.10:8080> DocumentRoot "/var/www/vhost2" </VirtualHost> [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.conf <VirtualHost 172.16.30.10:80> DocumentRoot "/var/www/vhost1" </VirtualHost> <VirtualHost 172.16.30.100:80> DocumentRoot "/var/www/vhost2" </VirtualHost> [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.conf <VirtualHost 172.16.30.10:80> DocumentRoot "/var/www/vhost1" ServerName vhost1.example.com </VirtualHost> <VirtualHost 172.16.30.10:80> DocumentRoot "/var/www/vhost2" ServerName vhost2.example.com </VirtualHost>
注意:DNS服務(wù)器中需要添加對應(yīng)的解析內(nèi)容。

訪問測試:


記得每次修改完配置文件后需要重啟服務(wù)。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
利用apache?ftpserver搭建ftp服務(wù)器的方法步驟
本文主要介紹了利用apache?ftpserver搭建ftp服務(wù)器的方法步驟,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-05-05
CentOS7 systemd添加自定義系統(tǒng)服務(wù)的方法
這篇文章主要介紹了CentOS7 systemd添加自定義系統(tǒng)服務(wù),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-03-03
谷歌云Google Cloud 啟用Ubuntu的SSH服務(wù)
默認情況下,當(dāng) Ubuntu 最初被安裝的時候,通過 SSH 進行遠程訪問是不被允許的,在 Ubuntu 上啟用 SSH 非常的簡單直接,需要的朋友可以參考下2023-12-12
Windows Apache2.4 VC9(ApacheHaus)詳細安裝配置教程
這篇文章主要介紹了Windows Apache2.4 VC9(ApacheHaus)詳細安裝配置教程,需要的朋友可以參考下2017-09-09
在CentOS / RHEL上設(shè)置 SSH 免密碼登錄的方法
本篇文章主要介紹了在CentOS / RHEL上設(shè)置 SSH 免密碼登錄的方法,自動登錄配置好以后,你可以通過它使用 SSH (Secure Shell)和安全復(fù)制 (SCP)來移動文件。2017-03-03

