●在同一臺(tái)服務(wù)器中運(yùn)行多個(gè)Web站點(diǎn),其中每一個(gè)站點(diǎn)并不獨(dú)立占用一臺(tái)真正的計(jì)算機(jī)
成都創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比桃源網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式桃源網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋桃源地區(qū)。費(fèi)用合理售后完善,十載實(shí)體公司更值得信賴。
? 虛擬Web主機(jī)指的是在同一臺(tái)服務(wù)器中運(yùn)行多個(gè)Web站點(diǎn),其中的每一個(gè)站點(diǎn)實(shí)際上并不獨(dú)自占用整個(gè)服務(wù)器,因此
被稱為“虛擬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
名稱欄目:構(gòu)建虛擬Web主機(jī)實(shí)例
文章位置:http://jinyejixie.com/article8/ghhjip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)、云服務(wù)器、網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、面包屑導(dǎ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)