https://blog.csdn.net/weisubao/article/details/43536723
解決方案:虛擬主機是設置在httpd-vhosts.conf還是vhosts.conf還是httpd.conf?
答案是:都可以。但是推薦在vhosts.conf中設置。
——官方文檔的舉例是在httpd.conf中設置的。
——百度一下會發現99%都是在httpd-vhosts.conf中設置的。但是這種設置會存在一些問題,比如設置后localhost打不開等等問題,雖然解決方案簡單,但是畢竟感覺不太保險。
——在vhosts.conf中設置的話,比較簡單,而且沒有什么幺蛾子問題。
<VirtualHost *:80>
ServerName localhost
DocumentRoot "E:\WWW"
DirectoryIndex index.html index.php
<Directory "E:\WWW">
Options Indexes
Order Allow,Deny
Allow From All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName www.hellocations.com
DocumentRoot "E:\hellocations"
DirectoryIndex index.html index.php
<Directory "E:\hellocations">
Options Indexes
Order Allow,Deny
Allow From All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName www.sina.com
DocumentRoot "E:\sina"
DirectoryIndex index.html index.php
<Directory "E:\sina">
Options Indexes
Order Allow,Deny
Allow From All
</Directory>
</VirtualHost>
當然,你需要在windows/system32/drivers/etc/hosts中設置幾個域名和IP的映射:
127.0.0.1 www.hellocations.com
127.0.0.1 www.sina.com
(1)問題1:是不是需要在httpd.conf中打開包含虛擬主機設置文件的那條語句?不需要。用phpstudy配置集成環境的話,我們看httpd.conf的配置文件,如下,發現vhosts.conf文件已經默認被包含了,而htttpd-vhosts.conf默認沒有包含,所以如果你執意要在httpd-vhosts.conf中設置虛擬主機的話,那么你需要把如下第二行的#去掉即可。
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
……
Include conf/vhosts.conf
# Secure (SSL/TLS) connections
#Include conf/extra/httpd-ssl.conf
(2)虛擬主機設置的格式以及注意事項?
——方法一:這個百度一下即可。
——方法二:查看官方文檔,或者下載一個離線的apache手冊。
——方法三:看配置文件中的示例。在httpd-vhosts.conf中有示例,如下。這也是為什么99%的人都在這個配置文件中配置的原因吧。不過apache的配置文件都是相通的。也就是說,有一個主配置文件httpd.conf,在其他地方還有很多分散的配置文件,當然這些分散的配置文件要想生效就需要在主配置文件中包含一下。思想和import或者include一樣一樣的。
# Add any other Virtual Hosts below
#<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot "/Apache24/docs/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>
——設置格式的注意事項,需要說明的是一般除了設置serverName和DocumentRoot外,還需要對目錄進行設置,即<Directory></Directory>的東西。否則會出現無權限訪問之類的問題,其他參數諸如錯誤日志、用戶訪問信息、別名設置等等可以設置也可以省略。
---------------------
作者:喂-不吃素的熊寶寶
來源:CSDN
原文:https://blog.csdn.net/weisubao/article/details/43536723
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!