apache怎么設(shè)置虛擬主機(jī)-創(chuàng)新互聯(lián)

創(chuàng)新互聯(lián)www.cdcxhl.cn八線動(dòng)態(tài)BGP香港云服務(wù)器提供商,新人活動(dòng)買多久送多久,劃算不套路!

網(wǎng)站建設(shè)公司,為您提供網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)頁設(shè)計(jì)及定制網(wǎng)站建設(shè)服務(wù),專注于企業(yè)網(wǎng)站建設(shè),高端網(wǎng)頁制作,對(duì)地磅秤等多個(gè)行業(yè)擁有豐富的網(wǎng)站建設(shè)經(jīng)驗(yàn)的網(wǎng)站建設(shè)公司。專業(yè)網(wǎng)站設(shè)計(jì),網(wǎng)站優(yōu)化推廣哪家好,專業(yè)成都網(wǎng)站營(yíng)銷優(yōu)化,H5建站,響應(yīng)式網(wǎng)站。

本篇文章給大家分享的是有關(guān)apache怎么設(shè)置虛擬主機(jī),小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

Apache虛擬主機(jī)的實(shí)現(xiàn)方式有3種:基于IP的虛擬主機(jī)、基于端口的虛擬主機(jī)、基于域名的虛擬主機(jī)。

一、基于IP

1. 假設(shè)服務(wù)器有個(gè)IP地址為192.168.1.10,使用ifconfig在同一個(gè)網(wǎng)絡(luò)接口eth0上綁定3個(gè)IP:

[root@localhost root]# ifconfig eth0:1 192.168.1.11
[root@localhost root]# ifconfig eth0:2 192.168.1.12
[root@localhost root]# ifconfig eth0:3 192.168.1.13

2. 修改hosts文件,添加三個(gè)域名與之一一對(duì)應(yīng):

192.168.1.11 www.test1.com
192.168.1.12 www.test2.com
192.168.1.13 www.test3.com

3. 建立虛擬主機(jī)存放網(wǎng)頁的根目錄,如在/www目錄下建立test1、test2、test3文件夾,其中分別存放1.html、2.html、3.html

/www/test1/1.html
/www/test2/2.html
/www/test3/3.html

4. 在httpd.conf中將附加配置文件httpd-vhosts.conf包含進(jìn)來,接著在httpd-vhosts.conf中寫入如下配置:

<VirtualHost 192.168.1.11:80>
ServerName www.test1.com
DocumentRoot /www/test1/
<Directory "/www/test1">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow From All
</Directory>
</VirtualHost>

<VirtualHost 192.168.1.12:80>
ServerName www.test1.com
DocumentRoot /www/test2/
<Directory "/www/test2">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow From All
</Directory>
</VirtualHost>

<VirtualHost 192.168.1.13:80>
ServerName www.test1.com
DocumentRoot /www/test3/
<Directory "/www/test3">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow From All
</Directory>
</VirtualHost>

5. 大功告成,測(cè)試下每個(gè)虛擬主機(jī),分別訪問www.test1.com、www.test2.com、www.test3.com

二、基于主機(jī)名

1. 設(shè)置域名映射同一個(gè)IP,修改hosts:

192.168.1.10 www.test1.com
192.168.1.10 www.test2.com
192.168.1.10 www.test3.com

2. 跟上面一樣,建立虛擬主機(jī)存放網(wǎng)頁的根目錄

/www/test1/1.html
/www/test2/2.html
/www/test3/3.html

3. 在httpd.conf中將附加配置文件httpd-vhosts.conf包含進(jìn)來,接著在httpd-vhosts.conf中寫入如下配置:

為了使用基于域名的虛擬主機(jī),必須指定服務(wù)器IP地址(和可能的端口)來使主機(jī)接受請(qǐng)求。可以用NameVirtualHost指令來進(jìn)行配置。 如果服務(wù)器上所有的IP地址都會(huì)用到, 你可以用*作為NameVirtualHost的參數(shù)。在NameVirtualHost指令中指明IP地址并不會(huì)使服務(wù)器自動(dòng)偵聽那個(gè)IP地址。 這里設(shè)定的IP地址必須對(duì)應(yīng)服務(wù)器上的一個(gè)網(wǎng)絡(luò)接口。

下一步就是為你建立的每個(gè)虛擬主機(jī)設(shè)定<VirtualHost>配置塊,<VirtualHost>的參數(shù)與NameVirtualHost指令的參數(shù)是一樣的。每個(gè)<VirtualHost>定義塊中,至少都會(huì)有一個(gè)ServerName指令來指定伺服哪個(gè)主機(jī)和一個(gè)DocumentRoot指令來說明這個(gè)主機(jī)的內(nèi)容存在于文件系統(tǒng)的什么地方。

如果在現(xiàn)有的web服務(wù)器上增加虛擬主機(jī),必須也為現(xiàn)存的主機(jī)建造一個(gè)<VirtualHost>定義塊。其中ServerName和DocumentRoot所包含的內(nèi)容應(yīng)該與全局的保持一致,且要放在配置文件的最前面,扮演默認(rèn)主機(jī)的角色。

NameVirtualHost *:80
<VirtualHost *:80>
ServerName *

DocumentRoot /www/

</VirtualHost>

<VirtualHost *:80>

ServerName www.test1.com

DocumentRoot /www/test1/

<Directory "/www/test1">

Options Indexes FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

</Directory>

</VirtualHost>

<VirtualHost *:80>

ServerName www.test2.com

DocumentRoot /www/test2/

<Directory "/www/test2">

Options Indexes FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

</Directory>

</VirtualHost>
<VirtualHost *:80>

ServerName www.test3.com

DocumentRoot /www/test3/

<Directory "/www/test3">

Options Indexes FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

</Directory>

</VirtualHost>

4. 大功告成,測(cè)試下每個(gè)虛擬主機(jī),分別訪問www.test1.com、www.test2.com、www.test3.com

三、基于端口

1. 修改配置文件

將原來的

Listen 80

改為

Listen 80
Listen 8080

2. 更改虛擬主機(jī)設(shè)置:

<VirtualHost 192.168.1.10:80>
DocumentRoot /var/www/test1/
ServerName www.test1.com
</VirtualHost>

<VirtualHost 192.168.1.10:8080>
DocumentRoot /var/www/test2
ServerName www.test2.com
</VirtualHost>

以上就是apache怎么設(shè)置虛擬主機(jī),小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見到或用到的。希望你能通過這篇文章學(xué)到更多知識(shí)。更多詳情敬請(qǐng)關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道。

網(wǎng)頁標(biāo)題:apache怎么設(shè)置虛擬主機(jī)-創(chuàng)新互聯(lián)
文章路徑:http://muchs.cn/article20/ejgjo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊(cè)網(wǎng)站內(nèi)鏈、網(wǎng)頁設(shè)計(jì)公司外貿(mào)網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站、定制網(wǎng)站

廣告

聲明:本網(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í)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司