1、httpd.conf修改
打开Apache目录下 conf\httpd.conf 文件,找到 Include conf/extra/httpd-vhosts.conf 这一行,删除行首#,取消注释
2、httpd-vhosts.conf配置
httpd-vhost.conf在 conf\extra\httpd-vhost.conf,打开后有一个写好的样例
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "${SRVROOT}/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log"
</VirtualHost>
DocumentRoot是我们需要配置的web项目的根目录
ServerName是你需要配置的本地域名
其他我们都可以不理,对DocumentRoot和ServerName修改即可
3、修改hosts文件
windows下通常在C:\Windows\System32\drivers\etc\下
添加ip 和我们刚刚添加的ServerName
格式如下
127.0.0.1 test.com
::1 test.com --
最后一步,重启apache服务器
本文介绍了在Windows环境下,如何配置Apache服务器以实现虚拟域名。首先,需要在httpd.conf中取消对httpd-vhosts.conf的注释。接着,编辑httpd-vhosts.conf文件,设置DocumentRoot为Web项目的根目录,并指定ServerName。最后,更新hosts文件,添加对应IP和ServerName的映射,完成配置后重启Apache服务器。
152

被折叠的 条评论
为什么被折叠?



