PHP开发当中使用XAMPP配置虚拟主机后,访问站点有时会出现403错误,因此需要在httpd-vhosts.conf文件做适当的配置!
下面是官方给出的默认配置
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
##NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ##ServerName or ##ServerAlias in any <VirtualHost> block.
#
##这是官方给出的示例配置
##<VirtualHost *:80>
##ServerAdmin webmaster@dummy-host.example.com
##DocumentRoot "C:/WebServer/htdocs/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" common
##</VirtualHost>
##<VirtualHost *:80>
##ServerAdmin webmaster@dummy-host.example.com
##DocumentRoot "C:/WebServer/htdocs/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" common
##</VirtualHost>
我们将其中壹个<VirtuaHost>标签按示例方式稍作修改为我们自己定义的路径和域名
<VirtualHost *:80>
ServerAdmin sudons@msn.cn
DocumentRoot "E:/WorkSpace/Web/Ankium"
ServerName www.ankium.com
ErrorLog "logs/www.ankium.com-error.log"
CustomLog "logs/www.ankium.com-access.log" common
</VirtualHost>
但是按上述示例配置虚拟主机后,访问出现403错误,因此需要添加<Directory>标签的内容
<VirtualHost *:80>
ServerAdmin sudons@msn.cn
DocumentRoot "E:/WorkSpace/Web/Ankium"
ServerName www.ankium.com
ErrorLog "logs/www.ankium.com-error.log"
CustomLog "logs/www.ankium.com-access.log" common
</VirtualHost>
<Directory "E:/WorkSpace/Web/Ankium">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
注意:因为配置虚拟主机后,XAMPP安装目录下默认的htdocs目录便再无法访问,为了访问默认站点里面的帮助文件,因此建议此处按虚拟站点方式,再添加默认站点!
<VirtualHost *:80>
ServerAdmin sudons@msn.cn
DocumentRoot "C:/WebServer/htdocs"
ServerName localhost
ErrorLog "logs/localhost.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
<Directory "C:/WebServer/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>