apache基于ip配置虛擬主機(jī)

apache基于ip配置虛擬主機(jī)

首先我們用記事本打開httpd.conf文件 ,該文件在apache的目錄下,如: d:appservapache2.2conf,修改如下兩處:

(推薦學(xué)習(xí):apache從入門到精通

LoadModule?vhost_alias_module?modules/mod_vhost_alias.so???//去掉前面的#,意思是啟用apache的虛擬主機(jī)功能,第203行
Include?conf/extra/httpd-vhosts.conf??//去掉#的意思是從httpd-vhosts.conf這個(gè)文件導(dǎo)入虛擬主機(jī)配置

配置虛擬主機(jī)后,不能用localhost 訪問,只需要把httpd.conf文件的ServerName localhost:80 那行注釋掉就可以了。

基于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è)域名與之一一對應(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>   ServerName?www.test1.com   DocumentRoot?/www/test1/   <directory> ?    Options?Indexes?FollowSymLinks     ?AllowOverride?None     ?Order?allow,deny   ?  Allow?From?All ? ?</directory></virtualhost><virtualhost>   ServerName?www.test1.com   DocumentRoot?/www/test2/   <directory> ?    Options?Indexes?FollowSymLinks     ?AllowOverride?None     ?Order?allow,deny   ?  Allow?From?All ? ?</directory></virtualhost><virtualhost>   ServerName?www.test1.com   DocumentRoot?/www/test3/   <directory> ?    Options?Indexes?FollowSymLinks     ?AllowOverride?None     ?Order?allow,deny   ?  Allow?From?All ? ?</directory></virtualhost>

完成,現(xiàn)在測試下每個(gè)虛擬主機(jī),分別訪問www.test1.com、www.test2.com、www.test3.com。

以上就是

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊8 分享