您好,登錄后才能下訂單哦!
●在同一臺(tái)服務(wù)器中運(yùn)行多個(gè)Web站點(diǎn),其中每一個(gè)站點(diǎn)并不獨(dú)立占用一臺(tái)真正的計(jì)算機(jī)
? 虛擬Web主機(jī)指的是在同一臺(tái)服務(wù)器中運(yùn)行多個(gè)Web站點(diǎn),其中的每一個(gè)站點(diǎn)實(shí)際上并不獨(dú)自占用整個(gè)服務(wù)器,因此
被稱(chēng)為“虛擬Web主機(jī)”。 通過(guò)虛擬Web主機(jī)服務(wù)可以充分利用服務(wù)器的硬件資源,從而大大降低網(wǎng)站構(gòu)建及運(yùn)行成本。
●基于域名的虛擬主機(jī) (應(yīng)用最為廣泛)
●基于IP地址的虛擬主機(jī)
●基于端口的虛擬主機(jī)
特征關(guān)系對(duì)應(yīng)分別如下
ip相同、端口相同,域名不同;
ip不同,端口不同;
構(gòu)建兩個(gè)虛擬web站點(diǎn)
1.www.jj.com
2.www.kk.com
實(shí)際流程如下:
使用一臺(tái)httpd服務(wù)器搭建,ip地址為192.168.68.145.具體構(gòu)建過(guò)程如下:
1.為虛擬主機(jī)提供域名解析
安裝bind和httpd服務(wù):yum install -y bind httpd
[root@localhost ~]# vim /etc/named.conf
[root@localhost ~]# head -21 /etc/named.conf |tail
options {
listen-on port 53 { any; };
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; };
[root@localhost ~]# vim /etc/named.rfc1912.zones
[root@localhost ~]# vim /etc/named.rfc1912.zones
[root@localhost ~]# head -34 /etc/named.rfc1912.zones | tail
zone "ll.com" IN {
type master;
file "ll.com.zone";
allow-update { none; };
};
zone "cc.com" IN {
type master;
file "cc.com.zone";
allow-update { none; };
[root@localhost ~]# cd /var/named/
[root@localhost named]# ls
data dynamic named.ca named.empty named.localhost named.loopback slaves
[root@localhost named]# cp -p named.localhost ll.com.zone
[root@localhost named]# vim ll.com.zone
[root@localhost named]# cp -p ll.com.zone cc.com.zone
[root@localhost named]# cat ll.com.zone
$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.68.145
[root@localhost named]# cat cc.com.zone
$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.68.145
[root@localhost named]# systemctl start named
[root@localhost named]# systemctl stop firewalld.service
[root@localhost named]# setenforce
usage: setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@localhost named]# setenforce 0
[root@localhost named]# systemctl start httpd
測(cè)試是否成功
[root@localhost named]# cd /etc/httpd/
[root@localhost httpd]# cd conf
[root@localhost conf]# ls
httpd.conf magic
[root@localhost conf]# mkdir extra
[root@localhost conf]# ls
extra httpd.conf magic
[root@localhost conf]# cd extra/
[root@localhost extra]# vim vhost.conf
[root@localhost extra]# cat vhost.conf
<VirtualHost *:80>
DocumentRoot "/var/www/html/ll/"
ServerName www.ll.com
ErrorLog "logs/www.ll.com.error_log"
CustomLog "logs/www.ll.com.access_log" common
<Directory "/var/www/html/">
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/html/cc/"
ServerName www.cc.com
ErrorLog "logs/www.cc.com.error_log"
CustomLog "logs/www.cc.com.access_log" common
<Directory "/var/www/html/">
Require all granted
</Directory>
</VirtualHost>
[root@localhost extra]# vim /etc/httpd/conf/httpd.conf
[root@localhost extra]# tail -2 /etc/httpd/conf/httpd.conf
IncludeOptional conf.d/*.conf
Include conf/extra/vhost.conf
[root@localhost extra]# systemctl restart httpd
根據(jù)以上過(guò)程可以繼續(xù)配置來(lái)完成基于端口的構(gòu)建:
[root@localhost ~]# vim /etc/httpd/conf/extra/vhost.conf
[root@localhost ~]# tail /etc/httpd/conf/extra/vhost.conf
<VirtualHost *:8080>
DocumentRoot "/var/www/html/cc02/"
ServerName www.cc.com
ErrorLog "logs/www.cc02.com.error_log"
CustomLog "logs/www.cc02.com.access_log" common
<Directory "/var/www/html/">
Require all granted
</Directory>
</VirtualHost>
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# mkdir cc02
[root@localhost html]# ls
cc cc02 ll
[root@localhost html]# cd cc02/
[root@localhost cc02]# vim index.html
[root@localhost cc02]# cat index.html
<h2>this is cc02 web</h2>
[root@localhost cc02]# vim /etc/httpd/conf/httpd.conf
[root@localhost cc02]# head -43 /etc/httpd/conf/httpd.conf | tail -3
Listen 192.168.68.145:80
Listen 192.168.68.145:8080
#Listen 80
[root@localhost cc02]# systemctl restart httpd
測(cè)試驗(yàn)證:輸入http://www.cc02.com:8080/即可
[root@localhost cc02]# vim /etc/httpd/conf/extra/vhost.conf
[root@localhost cc02]# cat /etc/httpd/conf/extra/vhost.conf
<VirtualHost 192.168.68.145:80>
DocumentRoot "/var/www/html/ll/"
#ServerName www.ll.com
ErrorLog "logs/www.ll.com.error_log"
CustomLog "logs/www.ll.com.access_log" common
<Directory "/var/www/html/">
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.68.146:80>
DocumentRoot "/var/www/html/ll02/"
#ServerName www.ll.com
ErrorLog "logs/www.ll02.com.error_log"
CustomLog "logs/www.ll02.com.access_log" common
<Directory "/var/www/html/">
Require all granted
</Directory>
</VirtualHost>
#<VirtualHost *:80>
# DocumentRoot "/var/www/html/cc/"
# ServerName www.cc.com
# ErrorLog "logs/www.cc.com.error_log"
# CustomLog "logs/www.cc.com.access_log" common
# <Directory "/var/www/html/">
# Require all granted
# </Directory>
#</VirtualHost>
#
#<VirtualHost *:8080>
# DocumentRoot "/var/www/html/cc02/"
# ServerName www.cc.com
# ErrorLog "logs/www.cc02.com.error_log"
# CustomLog "logs/www.cc02.com.access_log" common
# <Directory "/var/www/html/">
# Require all granted
# </Directory>
#</VirtualHost>
[root@localhost cc02]# mkdir ll02
[root@localhost cc02]# cd ll02
[root@localhost ll02]# vim index.html
[root@localhost ll02]# cat index.html
<h2>this is ll02 146</h2>
[root@localhost ll02]# vim /etc/httpd/conf/httpd.conf
[root@localhost ll02]# head -43 /etc/httpd/conf/httpd.conf | tail -5
# prevent Apache from glomming onto all bound IP addresses.
#
Listen 192.168.68.145:80
Listen 192.168.68.146:80
#Listen 192.168.68.145:8080
測(cè)試驗(yàn)證:輸入192.168.68.146
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。