Apache多站點配置
這種方法是配置不同的位址通路不同的檔案夾的配置
1:修改本機的hosts檔案,如下:
示例:
127.0.0.1 localhost
127.0.0.1 www.dede.com
127.0.0.1 www.phpcms.com
2: 打開appserv的安裝目錄,找到httpd.conf檔案,分别去掉下面兩行文字前面的#号。
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
去掉#意思是啟用apache的虛拟主機功能。
#Include conf/extra/httpd-vhosts.conf
去掉這一行的#意思是從conf/extra/httpd-vhosts.conf這個檔案導入虛拟主機配置。
3: 打開extra目錄内的httpd-vhosts.conf檔案,什麼都不管,直接在檔案底部加入自己要加的虛拟主機的資訊。如下面所示。
分别是給出一個管理者郵箱、指出此網站的根目錄、域名、和錯誤日志存放位置。注意目錄間隔最好用/而不是/ 。
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.phpzend.com
DocumentRoot E:/wamp/www/phpzend
ServerAlias www.phpzend.com
ErrorLog "logs/www.phpzend.com-error.log"
CustomLog "logs/www.phpzend.com-access.log" common
</VirtualHost>
*以上路徑中的斜線左斜右斜都可以。
4. 在httpd.conf中添加相應目錄
#wwww.phpzend.com
<Directory "E:/wamp/www/phpzend/">
Options Indexes FollowSymLinks
AllowOverride all Order Deny,
Allow Allow from all
</Directory>
将appserv的apache服務重新開機,就可以了,可以在各網站的根目錄下放一個index.html檔案,如果能看到,說明就對了。
第二種:是在同一個ip下面配置不同的端口的方法
打開appserv的安裝目錄,找到httpd.conf檔案,找到:
Listen 80
加入:
Listen 80
Listen 1000
Listen 1001
Listen 1002
然後參照虛拟主機的設定方法。不同的是:
<VirtualHost *:80> 這個後邊的端口号按自己需求更改就成了。
如果 弄完之後 出現403錯誤 那 在httpd.conf裡找到:
<Directory />
Options FollowSymLinks ExecCGI Indexes
AllowOverride None
Order deny,allow
Deny from all
Satisfy all
< /Directory>
更改為
<Directory />
Options FollowSymLinks ExecCGI Indexes
AllowOverride None
# Order deny,allow
# Deny from all
# Satisfy all
< /Directory>
用多端口配置多站點
配置1:開啟wampserver的虛拟目錄的支援
apache 的httpd.conf中找到Include conf/extra/httpd-vhosts.conf将前面的“;”去掉
配置2:設定多端口監聽
apache 的httpd.conf中
Listen 8080
Listen 8081
Listen 8082
Listen 8083
配置3:在httpd-vhosts.conf檔案中添加一組标簽
<VirtualHost *:8081>
ServerAdmin [email protected]
ServerName www.bingphp.com
DocumentRoot H:/wamp/www/canphp
ServerAlias www.bingphp.com
ErrorLog "logs/wordpress.localhost-error.log"
CustomLog "logs/wordpress.localhost-access.log" common
</VirtualHost>
#注意:ServerName的寫法,隻需寫此主機的域名或ip位址,localhost或127.0.0.1或具體的域名(www.bingphp.com 已認證hosts檔案映射到本機了)
若通路出現403、可配置apache的httpd.conf檔案
<Directory "H:/wamp/www/myblog">
Options Indexes FollowSymLinks
AllowOverride all
Order deny,allow
Allow from all
</Directory>