apache 配置vhost

方法一:
1.用记事本打开apache目录下httpd文件(在:C:\wamp\Apache2.4\conf),找到如下模块
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
去掉前面的#,这样就开启了httpd-vhosts虚拟主机文件。这时候重启wamp环境,无法打开localhost,需要在httpd- vhosts.conf配置一下。
2.用记事本打开httpd-vhosts文件(在:C:\wamp\Apache2.4\conf\extra)配置好localhost虚拟主机,参照httpd- vhosts文件中实例,修改成如下:
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.riceceongee.com
DocumentRoot "C:/wamp/Apache2.4/htdocs"
ServerName localhost
ServerAlias localhost
ErrorLog "logs/dummy-host2.riceceongee.com-error.log"
CustomLog "logs/dummy-host2.riceceongee.com-access.log" common
</VirtualHost>
3,重启Apache,发现localhost可以正常打开,配置localhost比较简单。
4.用记事本打开httpd-vhosts文件,照着上面配置blogdemo2.com主机
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.riceceongee.com
DocumentRoot "C:/wamp/Apache2.4/htdocs/blogdemo2/frontend/web/"
ServerName blogdemo2.com
ErrorLog "logs/dummy-host2.riceceongee.com-error.log"
CustomLog "logs/dummy-host2.riceceongee.com-access.log" common
</VirtualHost>
5.修改hosts文件,
window:C:\Windows\System32\drivers\etc
Linux: etc\hosts,
新增代码:
127.0.0.1  blogdemo2.com
6.重启Apache


方法二:
1.用记事本打开apache目录下httpd文件(在:C:\wamp\Apache2.4\conf),找到如下模块
LoadModule rewrite_module modules/mod_rewrite.so,
将其前面#号去掉启动,并粘贴如下代码

<VirtualHost *:80>
  ServerName blogdemo2.com
  DocumentRoot "C:/wamp/Apache2.4/htdocs/blogdemo2/frontend/web/"


  <Directory "C:/wamp/Apache2.4/htdocs/blogdemo2/frontend/web/">
  # use mod_rewrite for pretty URL support
  RewriteEngine on
  # If a directory or a file exists, use the request directly
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  # Otherwise forward the request to index.php
  RewriteRule . index.php


  # use index.php as index file
  DirectoryIndex index.php


  # ...other settings...
  </Directory>
  </VirtualHost>
2.重启apache

提示:如发现如下错误403 Forbidden错误
Forbidden
You don't have permission to access / on this server.
用记事本打开apache目录下httpd文件,
找到Deny from all,将其修改为
allow from all.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值