本文通過配置apache服務器,實現student.com,teacher.com兩個程序的配置,演示windows下 apache多域名配置。
PS:以下將apache安裝目錄簡稱為安裝目錄。
1、配置httpd.conf
打開安裝目錄下conf/httpd.conf 文件,找到
# Virtual hosts
# Include conf/extra/httpd-vhosts.conf
將Include conf/extra/httpd-vhosts.conf 前面#號去掉
2、配置httpd-vhosts.conf
打開安裝目錄下conf/extra/httpd-vhost.conf,刪掉原內容。
添加如下代碼:
<VirtualHost *:80>
ServerAdmin admin@student.com
DocumentRoot "D:/ProgramTools/projects/student"
ServerName student.com
ServerAlias www.student.com
ErrorLog "logs/student.com-error.log"
CustomLog "logs/student.com-access.log" common
<directory "D:/ProgramTools/projects/student">
Options FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from all
</directory>
</VirtualHost>
以上是配置student.com 程序,teacher.com配置類似它。
student.com 程序目錄在D:/ProgramTools/projects/student.
參考上述,在httpd-vhost.conf中配置teacher.com
3、添加host
在windows下需要在瀏覽器中通過student.com 訪問本地的student web application 需要添加host。
打開C:\Windows\System32\drivers\etc\hosts 文件,添加如下代碼:
127.0.0.1 student.com
127.0.0.1 www.student.com
127.0.0.1 teacher.com
127.0.0.1 www.teacher.com
4、准備student.com 和 teacher.com程序
這里每一個程序都僅僅只有一個index.php文件。內容分別輸出 hello student ! 和 hello teacher!
5、重啟apache服務器並瀏覽器輸入student.com和teacher.com測試。
PS:配置完畢vhost后會導致默認的www目錄不能訪問了。如果需要訪問。可以參考student程序的方法,配置一個localhost即可。
<VirtualHost *:80>
ServerAdmin 1849406240@qq.com
DocumentRoot "D:/ProgramTools/wamp/www"
ServerName localhost.com
ServerAlias www.localhost.com
ErrorLog "logs/localhost.com-error.log"
CustomLog "logs/localhost.com-access.log" common
<directory "D:/ProgramTools/wamp/www">
Options FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from all
</directory>
</VirtualHost>
---------------------
作者:ThelianPro
來源:CSDN
原文:https://blog.csdn.net/calm_thinker/article/details/50649874?utm_source=copy
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!