新聞中心
記事本打開httpd.conf文件 ,該文件在apache的目錄下,如: D:\AppServ\Apache2.2\conf,修改如下兩處:

LoadModule vhost_alias_module modules/mod_vhost_alias.so //去掉前面的#,意思是啟用apache的虛擬主機功能,第203行 Include conf/extra/httpd-vhosts.conf //去掉#的意思是從httpd-vhosts.conf這個文件導(dǎo)入虛擬主機配置
配置虛擬主機后 不能用localhost 訪問
只需要把httpd.conf文件的ServerName localhost:80 那行注釋掉 就可以了
一、基于IP
假設(shè)服務(wù)器有個IP地址為192.168.1.10,使用ifconfig在同一個網(wǎng)絡(luò)接口eth0上綁定3個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
修改hosts文件,添加三個域名與之一一對應(yīng):
192.168.1.11 www.test1.com
192.168.1.12 www.test2.com
192.168.1.13 www.test3.com
建立虛擬主機存放網(wǎng)頁的根目錄,如在/www目錄下建立test1、test2、test3文件夾,其中分別存放1.html、2.html、3.html
/www/test1/1.html
/www/test2/2.html
/www/test3/3.html
在httpd.conf中將附加配置文件httpd-vhosts.conf包含進來,接著在httpd-vhosts.conf中寫入如下配置:
ServerName www.test1.com
DocumentRoot /www/test1/
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow From All
ServerName www.test1.com
DocumentRoot /www/test2/
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow From All
ServerName www.test1.com
DocumentRoot /www/test3/
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow From All
大功告成,測試下每個虛擬主機,分別訪問www.test1.com、www.test2.com、www.test3.com
二、基于主機名
設(shè)置域名映射同一個IP,修改hosts:
127.0.0.1 gm.998gx.com
127.0.0.1 www.998gx.com
127.0.0.1 r.998gx.com
127.0.0.1 localhost
跟上面一樣,建立虛擬主機存放網(wǎng)頁的根目錄
/www/dxGM/index.php
/www/dxskadmin/index.php
/www/88qp/index.php
在httpd.conf中將附加配置文件httpd-vhosts.conf包含進來,接著在httpd-vhosts.conf中寫入如下配置:
為了使用基于域名的虛擬主機,必須指定服務(wù)器IP地址(和可能的端口)來使主機接受請求??梢杂肗ameVirtualHost指令來進行配置。 如果服務(wù)器上所有的IP地址都會用到, 你可以用*作為NameVirtualHost的參數(shù)。在NameVirtualHost指令中指明IP地址并不會使服務(wù)器自動偵聽那個IP地址。 這里設(shè)定的IP地址必須對應(yīng)服務(wù)器上的一個網(wǎng)絡(luò)接口。
下一步就是為你建立的每個虛擬主機設(shè)定配置塊,的參數(shù)與NameVirtualHost指令的參數(shù)是一樣的。每個定義塊中,至少都會有一個ServerName指令來指定伺服哪個主機和一個DocumentRoot指令來說明這個主機的內(nèi)容存在于文件系統(tǒng)的什么地方。
如果在現(xiàn)有的web服務(wù)器上增加虛擬主機,必須也為現(xiàn)存的主機建造一個定義塊。其中ServerName和DocumentRoot所包含的內(nèi)容應(yīng)該與全局的保持一致,且要放在配置文件的最前面,扮演默認主機的角色。
DocumentRoot “D:/phpstudy/WWW/dxGM”
ServerName gm.998gx.com
DocumentRoot “D:/phpstudy/WWW/88qp”
ServerName www.998gx.com
DocumentRoot “D:/phpstudy/WWW/dxskadmin”
ServerName r.998gx.com
DocumentRoot “D:/phpstudy/WWW”
ServerName localhost
4. 大功告成,測試下每個虛擬主機,分別訪問gm.998gx.com、www.998gx.com、r.998gx.com
三、基于端口
修改配置文件
將原來的
Listen 80
改為
Listen 80
Listen 8080
更改虛擬主機設(shè)置:
DocumentRoot /var/www/test1/
ServerName www.test1.com
DocumentRoot /var/www/test2
ServerName www.test2.com
到此這篇關(guān)于apache虛擬主機配置的三種方式(小結(jié))的文章就介紹到這了,更多相關(guān)apache虛擬主機配置內(nèi)容請搜索以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持!
成都創(chuàng)新互聯(lián)科技公司主營:網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、小程序制作、成都軟件開發(fā)、網(wǎng)頁設(shè)計、微信開發(fā)、成都小程序開發(fā)、網(wǎng)站制作、網(wǎng)站開發(fā)等業(yè)務(wù),是專業(yè)的成都做小程序公司、成都網(wǎng)站建設(shè)公司、成都做網(wǎng)站的公司。創(chuàng)新互聯(lián)公司集小程序制作創(chuàng)意,網(wǎng)站制作策劃,畫冊、網(wǎng)頁、VI設(shè)計,網(wǎng)站、軟件、微信、小程序開發(fā)于一體。
當前題目:apache虛擬主機配置的三種方式(小結(jié))
網(wǎng)址分享:http://www.5511xx.com/article/dhcpjih.html


咨詢
建站咨詢
