windows apache服务器配置多域名

本文通过配置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
版权声明:本文为博主原创文章,转载请附上博文链接!

转载于:https://www.cnblogs.com/xiaqiuchu/articles/10043642.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值