虚拟主机是设置在httpd-vhosts.conf仍是vhosts.conf仍是httpd.conf

https://blog.csdn.net/weisubao/article/details/43536723php

解决方案:虚拟主机是设置在httpd-vhosts.conf仍是vhosts.conf仍是httpd.conf?html

答案是:均可以。可是推荐在vhosts.conf中设置。web

 

——官方文档的举例是在httpd.conf中设置的。apache

——百度一下会发现99%都是在httpd-vhosts.conf中设置的。可是这种设置会存在一些问题,好比设置后localhost打不开等等问题,虽然解决方案简单,可是毕竟感受不太保险。windows

——在vhosts.conf中设置的话,比较简单,并且没有什么幺蛾子问题。.net

<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.comserver

(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.confhtm

(2)虚拟主机设置的格式以及注意事项?
——方法一:这个百度一下便可。blog

——方法二:查看官方文档,或者下载一个离线的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 版权声明:本文为博主原创文章,转载请附上博文连接!

相关文章
相关标签/搜索