配置虚拟主机
1、在hosts文件中添加你想要添加的虚拟域名;
2、在Apache配置文件中开启虚拟主机配置文件:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
3、然后在httpd-vhosts.conf文件中添加、设置虚拟主机的相关详细信息:
<VirtualHost *:80>
ServerAdmin 361466326@qq.com
DocumentRoot "E:/WWW/jlovel.com"
ServerName jlovel.com
# ---------------------------------------------------------------------------- #
#必须加上下面的这段描述,否则访问css/js/image等文件会报403 forbidden拒绝访问错误
<Directory />
Options FollowSymLinks
# AllowOverride None 不许可别人修改我们的页面
AllowOverride None
Order allow,deny #允许访问
Allow from all
</Directory>
# ---------------------------------------------------------------------------- #
ErrorLog "logs/jlovel-error.log"
CustomLog "logs/jlovel-access.log" common
</VirtualHost>
4、重启Apache访问页面即可
注:
1、配置了虚拟主机后,localhost访问失效了,解决办法:
注释conf/extra/httpd-vhosts.conf文件中以下内容,并添加一个localhost虚拟主机,如果只进行注释的话,localhost会访问唯一的虚拟主机地址:
# <VirtualHost _default_:80>
# DocumentRoot "/Apache24/htdocs"
#ServerName www.example.com:80
# </VirtualHost>
<VirtualHost *:80>
ServerAdmin 361466326@qq.com
DocumentRoot "E:/WWW"
ServerName localhost
<Directory />
Options FollowSymLinks
# AllowOverride None 不许可别人修改我们的页面
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ErrorLog "logs/error.log"
CustomLog "logs/access.log" common
</VirtualHost>

浙公网安备 33010602011771号