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.


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