[root@localhost ~]# yum install bind httpd -y //在服務(wù)器上安裝DNS與HTTP服務(wù)
[root@localhost ~]# cd /etc/ //進(jìn)入etc目錄
[root@localhost etc]# vim named.conf //進(jìn)入編輯DNS服務(wù)主配置文件
...//省略部分內(nèi)容...
options {
listen-on port 53 { any; }; //將監(jiān)聽I(yíng)P地址更改為any,監(jiān)聽所有地址
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
allow-query { any; }; //主機(jī)名更改為any,允許所有主機(jī)通過(guò)解析
...//省略部分內(nèi)容...
:wq //保存退出
[root@localhost etc]# vim named.rfc1912.zones //進(jìn)入編輯區(qū)域配置文件
...//省略部分內(nèi)容...
zone "kgc.com" IN { //更改域名
type master;
file "kgc.com.zone"; //更改數(shù)據(jù)文件名稱
allow-update { none; };
};
zone "aaa.com" IN { //更改域名
type master;
file "aaa.com.zone"; //更改數(shù)據(jù)文件名稱
allow-update { none; };
};
...//省略部分內(nèi)容...
[root@localhost etc]# cd /var/named/ //進(jìn)入?yún)^(qū)域數(shù)據(jù)文件存放目錄
[root@localhost named]# cp -p named.localhost kgc.com.zone //復(fù)制區(qū)域數(shù)據(jù)文件模板
[root@localhost named]# vim kgc.com.zone //進(jìn)入編輯模板
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
www IN A 192.168.144.133 //刪掉最后一行,更改為此行
:wq //保存退出
[root@localhost named]# cp -p kgc.com.zone aaa.com.zone //復(fù)制剛更改的數(shù)據(jù)文件,命名為aaa.com.zone,不需要更改內(nèi)容
[root@localhost named]# systemctl start named //啟動(dòng)DNS服務(wù)
[root@localhost named]# systemctl stop firewalld.service //關(guān)閉防火墻
[root@localhost named]# setenforce 0 //關(guān)閉增強(qiáng)性安全功能
[root@localhost html]# cd /etc/httpd/conf/ //進(jìn)入http服務(wù)配置文件目錄
[root@localhost conf]# mkdir extra //創(chuàng)建文件夾
[root@localhost conf]# ls //查看目錄
extra httpd.conf magic
[root@localhost extra]# vim vhost.conf //編輯子配置文件
<VirtualHost *:80>
DocumentRoot "/var/www/html/aaa/"
ServerName www.aaa.com
ErrorLog "logs/www.aaa.com.error_log"
CustomLog "logs/www.aaa.com.access_log" common
<Directory "/var/www/html">
Require all granted //編輯虛擬主機(jī)配置條目
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/html/kgc/"
ServerName www.kgc.com
ErrorLog "logs/www.kgc.com.error_log"
CustomLog "logs/www.kgc.com.access_log" common
<Directory "/var/www/html">
Require all granted
</Directory>
</VirtualHost>
~
:wq //保存退出
[root@localhost extra]# cd /var/www/html/ //進(jìn)入http服務(wù)網(wǎng)頁(yè)站點(diǎn)
[root@localhost html]# mkdir aaa kgc //創(chuàng)建目錄文件
[root@localhost html]# cd aaa/ //進(jìn)入目錄
[root@localhost aaa]# vim index.html //編輯默認(rèn)主頁(yè)
<h2>this is aaa web</h2> //編寫內(nèi)容
~
:wq //保存退出
[root@localhost aaa]# ls //查看目錄
index.html
[root@localhost aaa]# cd ../kgc/ //返回上一層并進(jìn)入kgc目錄
[root@localhost kgc]# vim index.html //編輯默認(rèn)網(wǎng)頁(yè)
<h2>this is kgc web</h2> //編輯內(nèi)容
~
:wq //保存退出
[root@localhost kgc]# ls //查看目錄
index.html
[root@localhost kgc]# vim /etc/httpd/conf/httpd.conf //進(jìn)入編輯http服務(wù)主配置文件
...//省略部分內(nèi)容...
# prevent Apache from glomming onto all bound IP addresses.
#
Listen 192.168.144.137:80 //打開ipv4監(jiān)聽地址,并更改為本機(jī)IP地址
#Listen 80 //關(guān)閉ipv6的監(jiān)聽地址
...//省略部分內(nèi)容...
# Load config files in the "/etc/httpd/conf.d" directory, if any.
IncludeOptional conf.d/*.conf
Include conf/extra/vhost.conf //在最后一行添加包含子配置文件目錄條目
:wq //保存退出
[root@localhost kgc]# systemctl start httpd //開啟http服務(wù)
[root@localhost kgc]# netstat -ntap | grep 80 //查看80端口是否開啟
tcp6 0 0 :::80 :::* LISTEN 2450/httpd
打開一臺(tái)win10客戶機(jī),更改DNS服務(wù)器地址,打開網(wǎng)頁(yè),測(cè)試基于不同域名構(gòu)建虛擬主機(jī)是否成功
市南ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來(lái)市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18980820575(備注:SSL證書合作)期待與您的合作!
此處實(shí)驗(yàn)就直接在上面的實(shí)驗(yàn)中更改配置,不重新操作
[root@localhost named]# vim /etc/httpd/conf/extra/vhost.conf
...//省略部分內(nèi)容...
<VirtualHost *:80>
DocumentRoot "/var/www/html/kgc/"
ServerName www.kgc.com
ErrorLog "logs/www.kgc.com.error_log"
CustomLog "logs/www.kgc.com.access_log" common
<Directory "/var/www/html">
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "/var/www/html/kgc02/"
ServerName www.kgc.com
ErrorLog "logs/www.kgc02.com.error_log"
CustomLog "logs/www.kgc02.com.access_log" common
<Directory "/var/www/html"> //復(fù)制上面的配置文件條目,并更改監(jiān)聽端口為8080,并將站點(diǎn)目錄、日志文件名更改為kgc02
Require all granted
</Directory>
</VirtualHost>
:wq //保存退出
[root@localhost named]# cd /var/www/html/
[root@localhost html]# mkdir kgc02
[root@localhost html]# cd kgc02/
[root@localhost kgc02]# vim index.html
<h2>this is kgc02 web</h2>
~
:wq
[root@localhost kgc02]# vim /etc/httpd/conf/httpd.conf
...//省略部分內(nèi)容...
# prevent Apache from glomming onto all bound IP addresses.
#
Listen 192.168.144.137:80
Listen 192.168.144.137:8080
#Listen 80
...//省略部分內(nèi)容...
:wq
[root@localhost kgc02]# systemctl restart httpd
在win10客戶端驗(yàn)證基于端口的虛擬主機(jī)配置
在這里先給Linux服務(wù)器虛擬機(jī)添加一張網(wǎng)卡,獲取另一個(gè)IP地址
在虛擬機(jī)中獲取IP地址
[root@localhost ~]# ifconfig //查看網(wǎng)卡信息
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.144.137 netmask 255.255.255.0 broadcast 192.168.144.255
inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link>
inet6 fe80::ad78:663f:1f02:22e4 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:72:65:cb txqueuelen 1000 (Ethernet)
RX packets 14117 bytes 10290025 (9.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6337 bytes 767788 (749.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.144.143 netmask 255.255.255.0 broadcast 192.168.144.255 //成功獲取IP地址
inet6 fe80::d65e:47b1:916d:de6c prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:72:65:d5 txqueuelen 1000 (Ethernet)
RX packets 115 bytes 20495 (20.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 79 bytes 17837 (17.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
...//省略部分內(nèi)容...
[root@localhost ~]# vim /etc/httpd/conf/extra/vhost.conf //進(jìn)入編輯http服務(wù)子配置文件
<VirtualHost 192.168.144.137:80> //更改為固定IP地址
DocumentRoot "/var/www/html/aaa/"
ServerName www.aaa.com
ErrorLog "logs/www.aaa.com.error_log"
CustomLog "logs/www.aaa.com.access_log" common
<Directory "/var/www/html">
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.144.143:80> //復(fù)制上面配置條,更改IP地址
DocumentRoot "/var/www/html/aaa02/" //更改站點(diǎn)文件
ServerName www.naaa.com //更改域名
ErrorLog "logs/www.aaa02.com.error_log" //更改錯(cuò)誤日志文件名
CustomLog "logs/www.aaa02.com.access_log" common //更改日志文件名
<Directory "/var/www/html">
Require all granted
</Directory>
</VirtualHost>
:wq //保存退出
[root@localhost ~]# vim /etc/named.rfc1912.zones //編輯DNS區(qū)域配置文件
...//省略部分內(nèi)容...
zone "aaa.com" IN {
type master;
file "aaa.com.zone";
allow-update { none; };
};
zone "naaa.com" IN {
type master; //添加新的區(qū)域配置文件
file "naaa.com.zone";
allow-update { none; };
};
...//省略部分內(nèi)容...
:wq //保存退出
[root@localhost ~]# cd /var/named/ //進(jìn)入?yún)^(qū)域數(shù)據(jù)文件存放目錄
[root@localhost named]# cp -p aaa.com.zone naaa.com.zone //復(fù)制區(qū)域數(shù)據(jù)文件
[root@localhost named]# vim naaa.com.zone //進(jìn)入編輯新的區(qū)域數(shù)據(jù)文件
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
www IN A 192.168.144.143 //更改IP地址
~
:wq //保存退出
[root@localhost named]# cd /var/www/html/ //進(jìn)入http服務(wù)站點(diǎn)
[root@localhost html]# mkdir aaa02 //創(chuàng)建新的站點(diǎn)目錄
[root@localhost html]# cd aaa02/ //進(jìn)入目錄
[root@localhost aaa02]# vim index.html //編輯默認(rèn)主頁(yè)文件
<h2>this is 143 aaa02 web</h2> //編輯網(wǎng)頁(yè)內(nèi)容
:wq //保存退出
[root@localhost aaa02]# vim /etc/httpd/conf/httpd.conf //編輯http服務(wù)主配置文件
...//省略部分內(nèi)容...
# prevent Apache from glomming onto all bound IP addresses.
#
Listen 192.168.144.137:80
Listen 192.168.144.143:80 //編輯監(jiān)聽新的IP地址
#Listen 80
...//省略部分內(nèi)容...
:wq //保存退出
[root@localhost aaa02]# systemctl restart httpd //重啟http服務(wù)
[root@localhost aaa02]# systemctl restart named //重啟DNS服務(wù)
在win10客戶機(jī)中驗(yàn)證基于IP地址建立的虛擬主機(jī)
本文名稱:CentOS7中構(gòu)建虛擬主機(jī)(實(shí)驗(yàn)篇)
地址分享:http://aaarwkj.com/article12/gjgsgc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷、App開發(fā)、網(wǎng)站內(nèi)鏈、服務(wù)器托管、做網(wǎng)站、微信公眾號(hào)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)