雷火电竞-中国电竞赛事及体育赛事平台

歡迎來到入門教程網!

Linux/apache

當前位置:主頁 > 服務器 > Linux/apache >

linux7下虛擬主機的三種實現(xiàn)方式

來源:本站原創(chuàng)|時間:2020-01-10|欄目:Linux/apache|點擊:

一、 相同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服務器中需要添加對應的解析內容。


訪問測試:


記得每次修改完配置文件后需要重啟服務。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持我們。

上一篇:linux ssh端口轉發(fā)的三種方式

欄    目:Linux/apache

下一篇:Shell腳本實戰(zhàn)之DNS主從同步腳本實例

本文標題:linux7下虛擬主機的三種實現(xiàn)方式

本文地址:http://www.jygsgssxh.com/a1/Linux_apache/10768.html

網頁制作CMS教程網絡編程軟件編程腳本語言數據庫服務器

如果侵犯了您的權利,請與我們聯(lián)系,我們將在24小時內進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網 版權所有