(含phpstudy)Windows下配置虚拟域名

环境:集成环境phstudy 
操作系统: windows 10 
1):修改hosts文件,添加虚拟域名->C:\Windows\System32\drivers\etc\hostshosts
在hosts文件最下面添加你的地址和对应的虚拟域名,比如:127.0.0.1 test.com

2):找到配置文件 httpd.conf 
位置在你安phpstudy的盘符比如 F:\phpStudy\PHPTutorial\Apache\conf 
path
打开 httpd.conf 文件,ctrl+f 搜索 httpd-vhost ,就会找到 Include conf/extra/httpd-vhosts.conf,删掉前面的注释“#”,然后再搜索 servername 找到下图,注释(在前面加上#)后面会用到↓ 
这里写图片描述

3):第一个坑,很多教程都叫去同级目录 extra 目录中找 httpd-vhosts.conf 修改,但在phpstudy中,就是同级目录中的vhosts.conf文件 
这里写图片描述 
这里写图片描述

continue->修改vhosts文件(原内容全部删掉),复制修改为自己的信息即可(我写的注释记得删掉)

#1
<VirtualHost *:80>
    DocumentRoot "F:\phpStudy\PHPTutorial\WWW"
    ServerName localhost
    ServerAlias 
  <Directory "F:\phpStudy\PHPTutorial\WWW">
      AllowOverride All
      Order allow,deny
      Allow from all
      Require all granted
  </Directory>
</VirtualHost>

#2
<VirtualHost *:80>
    DocumentRoot "F:\phpStudy\PHPTutorial\WWW"
    ServerName 127.0.0.1
    ServerAlias 
  <Directory "F:\phpStudy\PHPTutorial\WWW">
      AllowOverride All
      Order allow,deny
      Allow from all
      Require all granted
  </Directory>
</VirtualHost>

#3
<VirtualHost *:80>
 DocumentRoot "F:\phpStudy\PHPTutorial\WWW\hopes\tp5\public" //目标目录
 ServerName community.hope.com //hosts文件中添加的虚拟域名
</VirtualHost>
<Directory "F:\phpStudy\PHPTutorial\WWW\hopes\tp5\public"> //目标目录
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

<VirtualHost *:80>

DocumentRoot "F:\phpStudy\PHPTutorial\WWW"

ServerName localhost

ServerAlias <Directory "F:\phpStudy\PHPTutorial\WWW">

AllowOverride

All Order allow,deny

Allow from all

Require all granted

</Directory>

</VirtualHost>

(PS:为什么要这么写?因为先前我们去掉httpd-conf中的 #Include conf/extra/httpd-vhosts.conf 的#之后,虽然设置的虚拟域名可以访问了,但是原来通过localhost和127.0.0.1的方式访问却会404,因为想继续以这两种形式进行访问,所以才会有之前我们注释servername的步骤,然后#1,#2也就是把这两种形式也设置成了虚拟站点,得以继续访问。不要忘了在hosts文件中也添加127.0.0.1 localhost 哦!我是之前就有的。那这是我踩坑后得出的结论,每个人可能遇到情况都不太一样,如果您有更好更简便的方式,或者有不同的意见请在下面评论区分享出来,我会非常开心的O(∩_∩)O) 
重启Apache,成功!

4):还可以直接通过phpstudy中的站点域名管理快速配置,我的有问题,所以跳过。 
这里写图片描述

END.

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值