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 [email protected]
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 [email protected]
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.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章