溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Apache構(gòu)建虛擬主機(jī)

發(fā)布時(shí)間:2020-08-06 00:34:24 來源:網(wǎng)絡(luò) 閱讀:12531 作者:wx5d3fd1efe40e3 欄目:網(wǎng)絡(luò)管理

一、虛擬Web主機(jī)

在同一臺(tái)物理服務(wù)器中運(yùn)行多個(gè)Web站點(diǎn),其中每-一個(gè)站點(diǎn)并不獨(dú)立占用-臺(tái)真正的計(jì)算機(jī)

二、httped支持的虛擬主機(jī)類型

  • 基于域名的虛擬主機(jī)

  • 基于IP地址的虛擬主機(jī)(雙網(wǎng)卡,多網(wǎng)卡,多IP地址。不推薦,多申請(qǐng)公網(wǎng)IP要多花錢)

  • 基于端口的虛擬主機(jī)(端口不同,訪問不同的網(wǎng)站)

三、構(gòu)建虛擬主機(jī)

基于域名:

1、a、為虛擬主機(jī)提供域名解析。首先配置主配置文件

[root@localhost?conf]#?vim?/etc/named.conf?
options?{
????????listen-on?port?53?{?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;?};??????????????????????//?允許范圍

Apache構(gòu)建虛擬主機(jī)

b、配置區(qū)域配置文件

[root@localhost?conf]#?vim?/etc/named.rfc1912.zones????????
zone?"kgc.com"?IN?{
????????type?master;
????????file?"kgc.com.zone";
????????allow-update?{?none;?};
};
zone?"accp.com"?IN?{
????????type?master;
????????file?"accp.com.zone";
????????allow-update?{?none;?};

Apache構(gòu)建虛擬主機(jī)

c、配置區(qū)域數(shù)據(jù)配置文件

[root@localhost?conf]#??cp?-p?named.localhost?accp.com.zone???????
root@localhost?conf]#?vim?accp.com.zone
[root@localhost?conf]#??cp?-p?named.localhost?kgc.com.zone
[root@localhost?conf]#?vim?kgc.com.zone

Apache構(gòu)建虛擬主機(jī)Apache構(gòu)建虛擬主機(jī)

Apache構(gòu)建虛擬主機(jī)

2、a、添加虛擬主機(jī)配置

[root@localhost?conf]#?cd?/etc/httpd????????//進(jìn)入httpd系統(tǒng)配置文件中
[root@localhost?httpd]#?ls
conf??conf.d??conf.modules.d??logs??modules??run
[root@localhost?httpd]#?cd?conf
[root@localhost?conf]#?ls
httpd.conf??magic
[root@localhost?conf]#?mkdir?extra??????????//于conf目錄下創(chuàng)建目錄
[root@localhost?conf]#?ls
extra??httpd.conf??magic
[root@localhost?conf]#?cd?extra/
[root@localhost?extra]#?vim?vhost.conf???????//于新目錄中添加虛擬主機(jī)配置

Apache構(gòu)建虛擬主機(jī)

b、配置網(wǎng)站信息,指定虛擬主機(jī)域名配置路徑

[root@localhost?httpd]#?cd?/var/www/html/
[root@localhost?html]#?ls
[root@localhost?html]#?mkdir?accp?kgc??????????//創(chuàng)建目錄
[root@localhost?html]#?ls
accp??kgc
[root@localhost?html]#?cd?accp/
[root@localhost?accp]#?ls
[root@localhost?accp]#?vim?index.html???????????//配置網(wǎng)站信息
[root@localhost?accp]#?cd?../
[root@localhost?html]#?cd?kgc/
[root@localhost?kgc]#?vim?index.html
[root@localhost?kgc]#?cd?/etc/httpd/
[root@localhost?httpd]#?ls
conf??conf.d??conf.modules.d??logs??modules??run
[root@localhost?httpd]#?cd?conf
[root@localhost?conf]#?ls
extra??httpd.conf??magic
[root@localhost?conf]#?vim?httpd.conf???????//指定配置文件路徑
[root@localhost?conf]#?systemctl?start?httpd??????????//啟動(dòng)httpd服務(wù)。服務(wù)啟動(dòng)失敗
Job?for?httpd.service?failed?because?the?control?process?exited?with?error?code.?See?"systemctl?status?httpd.service"?and?"journalctl?-xe"?for?details.??????????
[root@localhost?conf]#?cd?extra/
[root@localhost?extra]#?vim?vhost.conf???????????????????????//需在配置文件中添加common命令
[root@localhost?extra]#?systemctl?start?httpd????????????????//配置完成后啟動(dòng)httpd服務(wù)

Apache構(gòu)建虛擬主機(jī)

Apache構(gòu)建虛擬主機(jī)

Apache構(gòu)建虛擬主機(jī)

Apache構(gòu)建虛擬主機(jī)

Apache構(gòu)建虛擬主機(jī)

3、登陸win10,查看實(shí)驗(yàn)結(jié)果

Apache構(gòu)建虛擬主機(jī)

Apache構(gòu)建虛擬主機(jī)

二、基于IP。配置添加虛擬主機(jī)端口信息,創(chuàng)建新目錄配置網(wǎng)站信息,修改監(jiān)聽端口號(hào)

1、添加一塊網(wǎng)卡,設(shè)置雙網(wǎng)卡。


[root@localhost?extra]#?vim?vhost.conf?????????????配置虛擬主機(jī)IP
[root@localhost?extra]#?cd?/var/www/html??????
[root@localhost?html]#?ls
accp??kgc??kgc02
[root@localhost?html]#?mkdir?accp02?????????????在/var/www/html下創(chuàng)建新目錄,添加編輯網(wǎng)站信息
[root@localhost?html]#?cd?accp02/
[root@localhost?accp02]#?vim?index.html
[root@localhost?accp02]#?vim?/etc/httpd/conf/httpd.conf???????????修改監(jiān)聽I(yíng)P端口號(hào)

Apache構(gòu)建虛擬主機(jī)

Apache構(gòu)建虛擬主機(jī)

Apache構(gòu)建虛擬主機(jī)

Apache構(gòu)建虛擬主機(jī)

Apache構(gòu)建虛擬主機(jī)

Apache構(gòu)建虛擬主機(jī)

區(qū)域數(shù)據(jù)配置文件也要做相應(yīng)的映射。

三、基于端口(以www.kgc.com為例),配置添加虛擬主機(jī)端口信息,創(chuàng)建新目錄配置網(wǎng)站信息,修改監(jiān)聽端口號(hào)


[root@localhost?extra]#?vim?vhost.conf??????????????配置虛擬主機(jī)配置文件
[root@localhost?extra]#?cd?/var/www/html/
[root@localhost?html]#?ls
accp??kgc
[root@localhost?html]#?mkdir?kgc02????????????????//創(chuàng)建kgc02新目錄
[root@localhost?html]#?ls??
accp??kgc??kgc02
[root@localhost?html]#?cd?kgc02/
[root@localhost?kgc02]#?vim?index.html??????????????//配置網(wǎng)站信息

Apache構(gòu)建虛擬主機(jī)

Apache構(gòu)建虛擬主機(jī)

2、配置監(jiān)聽端口號(hào)

[root@localhost?kgc02]#?vim?/etc/httpd/conf/httpd.conf?????
[root@localhost?kgc02]#?systemctl?restart?httpd????重啟httpd服務(wù)

Apache構(gòu)建虛擬主機(jī)

3、登陸win10,查看實(shí)驗(yàn)結(jié)果

Apache構(gòu)建虛擬主機(jī)


關(guān)于apache構(gòu)建虛擬主機(jī)三種方式全部介紹完畢。更多干貨點(diǎn)我主頁查收。

向AI問一下細(xì)節(jié)

免責(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)容。

AI