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

posted @   夏秋初  阅读(1128)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示