基于域名配置Apache步骤
1.配置本机hosts文件
文件路径:C:\Windows\System32\drivers\etc
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
# 自己添加的
127.0.0.1 www.proj.com
127.0.0.1 www.swg.com
修改好了自己保存。如果不能保存,请以管理员身份运行文本编辑器,进行编辑。
2.修改Apache httpd.conf配置文件
文件路径:(Apache安装目录:C:\laragon\bin\apache\httpd-2.4.35-win32-VC15\conf)
取消一下行前的注释-保存:(搜索关键字:httpd-vhosts、mod_vhost_alias)
Include conf/extra/httpd-vhosts.conf
LoadModule vhost_alias_module modules/mod_vhost_alias.so
3.修改Apache httpd-vhost.conf配置文件
文件目录:(httpd-vhost.conf 在Apache安装目录的conf/extra/下)
# 样例
#<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host2.example.com
# DocumentRoot "${SRVROOT}/docs/dummy-host2.example.com"
# ServerName dummy-host2.example.com
# ErrorLog "logs/dummy-host2.example.com-error.log"
# CustomLog "logs/dummy-host2.example.com-access.log" common
#</VirtualHost>
# 自己添加的虚拟主机
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "F:\web\trunk\restaurant_verify\web" # 项目路径
ServerName www.proj.com # 域名,和hosts配置里面写的相对应
<Directory "F:\web\trunk\restaurant_verify\web">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
保存
4.重启Apache
5.测试
打开浏览器,地址栏输入:www.proj.com, 浏览器正常响应。