Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9262553
  • 博文数量: 1669
  • 博客积分: 16831
  • 博客等级: 上将
  • 技术积分: 12594
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-25 07:23
个人简介

柔中带刚,刚中带柔,淫荡中富含柔和,刚猛中荡漾风骚,无坚不摧,无孔不入!

文章分类

全部博文(1669)

文章存档

2023年(4)

2022年(1)

2021年(10)

2020年(24)

2019年(4)

2018年(19)

2017年(66)

2016年(60)

2015年(49)

2014年(201)

2013年(221)

2012年(638)

2011年(372)

分类: 系统运维

2016-03-21 10:43:41

虚拟主机是设置在httpdvhosts.conf还是vhosts.conf还是httpd.conf

来源:IT165收集  发布日期:2015-02-06 23:41:45

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

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

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

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

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

 

01.
02.    ServerName    localhost
03.    DocumentRoot  "E:WWW"
04.    DirectoryIndex index.html index.php
05.    
06.        Options Indexes
07.        Order Allow,Deny
08.        Allow From All
09.    
10.
11.  
12.
13.    ServerName   
14.    DocumentRoot  "E:hellocations"
15.    DirectoryIndex index.html index.php
16.    
17.        Options Indexes
18.        Order Allow,Deny
19.        Allow From All
20.    
21.
22.  
23.
24.    ServerName   
25.    DocumentRoot  "E:sina"
26.    DirectoryIndex index.html index.php
27.    
28.        Options Indexes
29.        Order Allow,Deny
30.        Allow From All
31.    
32.

当然,你需要在windows/system32/drivers/etc/hosts中设置几个域名和IP的映射:

 

 

1.127.0.0.1   
2.127.0.0.1   

(1)问题1:是不是需要在httpd.conf中打开包含虚拟主机设置文件的那条语句?不需要。用phpstudy配置集成环境的话,我们看httpd.conf的配置文件,如下,发现vhosts.conf文件已经默认被包含了,而htttpd-vhosts.conf默认没有包含,所以如果你执意要在httpd-vhosts.conf中设置虚拟主机的话,那么你需要把如下第二行的#去掉即可。

 

 

1.# Virtual hosts
2.#Include conf/extra/httpd-vhosts.conf
3.  
4.……
5.Include conf/vhosts.conf
6.  
7.# Secure (SSL/TLS) connections
8.#Include conf/extra/httpd-ssl.conf

(2)虚拟主机设置的格式以及注意事项?

 

——方法一:这个百度一下即可。

——方法二:查看官方文档,或者下载一个离线的apache手册。

——方法三:看配置文件中的示例。在httpd-vhosts.conf中有示例,如下。这也是为什么99%的人都在这个配置文件中配置的原因吧。不过apache的配置文件都是相通的。也就是说,有一个主配置文件httpd.conf,在其他地方还有很多分散的配置文件,当然这些分散的配置文件要想生效就需要在主配置文件中包含一下。思想和import或者include一样一样的。

 

01.# Add any other Virtual Hosts below
02.  
03.#
04.#    ServerAdmin webmaster@dummy-host.example.com
05.#    DocumentRoot "/Apache24/docs/dummy-host.example.com"
06.#    ServerName dummy-host.example.com
07.#    ServerAlias
08.#    ErrorLog "logs/dummy-host.example.com-error.log"
09.#    CustomLog "logs/dummy-host.example.com-access.log" common
10.#

——设置格式的注意事项,需要说明的是一般除了设置serverName和DocumentRoot外,还需要对目录进行设置,即的东西。否则会出现无权限访问之类的问题,其他参数诸如错误日志、用户访问信息、别名设置等等可以设置也可以省略。

 

阅读(1257) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~