、配置环境
①:XAMPP
②:windows10 家庭版
③:编译器。我这里使用的是phpstorm,你也可以使用其他的编译器,电脑自带的文本编译器也行。
二、在httpd-vhosts.conf文件中,配置本地虚拟主机路径和域名
按照上图所示进入该目录。进入改目录后找到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 “E:/XAMPP/XAMPP/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 “E:/XAMPP/XAMPP/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
##<Directory 目录路径>…< /Directory>在httpd-vhosts.conf文件中,这一行没有。但是在配置站点时,这一行是非常有用的,这里我就加上了
##</VirtualHost>
指令 说明
ServerAdmin 用来设置服务器返回给客户端的错误信息中包含的管理员邮件地址。便于用户在收到错误信息后能及时与管理员取得联系
ServerName 用来设置服务器用于辨识自己的主机名和端口号。主要用于创建重定向URL。
DocumentRoot 用来设置httpd提供服务的目录。即你所在项目入口处的文件夹。
ErrorLog 来设置当服务器遇到错误时记录错误日志的文件。如果file-path不是以/开头的绝对路径,那么将会被认为是一个相对于ServerRoot的相对路径。
CustomLog 设置日志文件,并指明日志文件所用的格式(通常通过格式的名字)。
<Directory 目录路径>…< /Directory> 为主目录或虚拟目录设置权限。
<Directory 目录路径>…< /Directory>虚拟目录设置权限
命令参数 说明
Indexes 允许目录浏览
MultiViews 允许内容协商的多重视图
All All包含了除MultiViews之外的所有特性,如果没有Options语句,默认为All
ExecCGI 允许在该目录下执行CGI脚本
FollowSymLinks 可以在该目录中使用符号连接
Includes 允许服务器端包含功能
IncludesNoExec 允许服务器端包含功能,但禁用执行CGI脚本
① DirectoryIndex index.html index.htm index.php设置访问目录后进入的默认文件
②AllowOverride all 定义位于每个目录下.htaccess(访问控制)文件中的指令类型。none为禁止使用.htaccess文件。
③Order Deny,Allow
Allow from all
设置缺省的访问权限与Allow和Deny语句的处理顺序
deny, allow:缺省允许所有客户机的访问,且Deny语句在Allow语句之前被匹配。如果某条件既匹配Deny语句又匹配Allow语句,则Allow语句会起作用(因为Allow语句覆盖了Deny语句)。
allow, deny:缺省禁止所有客户机的访问,且Allow语句在Deny语句之前被匹配。如果某条件既匹配Deny语句又匹配Allow语句,则Deny语句会起作用(因为Deny语句覆盖了Allow语句)。
eg.
Order deny ,allow
Deny from baidu.com
Deny from 192.168.66.6
除了来自baidu.com域和ip地址为192.168.66.6的客户机外,允许所有客户机访问
Order deny ,allow
Allow from 192.168.66.6
Deny from 192.168.66.1
既匹配Deny语句又匹配Allow语句,由于allow语句覆盖了deny语句,所以是允许所有客户机访问
摘自Apache里的httpd-vhosts.conf详解
在我电脑上配置为
VirtualHost *:80>
#配置站点管理员的邮箱,当站点报500错误时会在页面提示错误信息,并列出管理员邮箱
ServerAdmin webmaster@dummy-host2.example.com
#站点根目录
DocumentRoot “E:/PHPstorm/www”
#站点绑定的域名
ServerName www.supremeh.com
#站点的别名
ServerAlias supremeh.com
#错误日志的存储位置,logs目录在apache下
ErrorLog “logs/dummy-host2.example.com-error.log”
#正常访问日志的存储位置,common是日志的记录规则
CustomLog “logs/dummy-host2.example.com-access.log” common
#对目录的详细配置
<Directory “E:/PHPstorm/www”>
#Options FollowSymLinks
#不允许重写,允许重写为 all
AllowOverride None
Order allow,deny
#允许所有访问
Allow from all
#允许显示站点的文件结构,不显示文件结构可以写为 -indexes
Options +indexes
</Directory>
</VirtualHost>
<VirtualHost _default_:80>
DocumentRoot “E:/PHPstorm/www”
ServerName localhost
Options +indexes
</VirtualHost>
三、在httpd.conf文件中 ,去掉mod_rewrite.so注释
四、在httpd.conf文件中 ,去掉httpd-vhosts.conf注释
五、配置httpd.conf文件中,Directory
有的博文上面有这一步,有的没有。这里我把我的配置放上去,如果没有用,大家可以不用
六、修改hosts文件
打开hosts文件,并修改
最后不要忘了重启apache
如果有配置中出什么问题,可以私信
————————————————
版权声明:本文为CSDN博主「Kinghiee」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_42683219/article/details/100727441
转载请注明:XAMPP中文组官网 » 本地安装XAMPP配置虚拟站点