整理一下Windows 环境从Apache 2.2 改成Apache 2.4.1 后httpd.conf 的设定笔记及遇到的问题
若有兴趣可以先看一下官方文件说明2.4 的差异( 我当然是...没有看完Orz )
http://httpd.apache.org/docs/2.4/upgrading.html
http://httpd.apache.org/docs/2.4/new_features_2_4.html
/*2012.12.25 补充*/
apache 2.4.3版有对window版的ssl bug做修正,bug说明 http://www.apachelounge.com/viewtopic.php?p=22306
这个bug 简而言之就是会让443 的页面连线挂点...
1. 权限设定方式变更
原本使用Order Deny / Allow的方式,改用Require
官方范例:
Order deny , allow Deny from all
在2.4 需要改成
Require all denied
比较常用到的有以下几种
Require all denied
Require all granted
Require host xxx.com
Require ip 192.168.1 192.168.2
Require local
注意:若有设定在.htaccess中的也要修改
详细指令说明: http://httpd.apache.org/docs/2.4/mod/mod_authz_core.html#require
2. 设定Log 纪录方式变更
RewriteLogLevel指令改为logLevel
LogLevel 设定第一个值是针对整个Apache 设的预设等级,后方可以对指定的模组修改此模组的Log 记录等级
范例:
LogLevel warn rewrite: warn
详细指令说明请查看: http://httpd.apache.org/docs/2.4/mod/core.html#loglevel
3. Namevirtualhost 被移除
虽然我查官方文件是还有NameVirtualHost指令,但是执行时会出现错误。
官方文件也写了这个指令目前是无作用的,因此删掉此设定。
详细说明: http://httpd.apache.org/docs/2.4/mod/core.html#namevirtualhost
4. 其他要多载入的模组
使用网站压缩除了开启mod_deflate外,在Apache 2.4中还需要多开mod_filter
使用SSL凭证除了开启mod_ssl外,在Apache 2.4中还需要多开mod_socache_shmcb
5. 在windows 环境建议的设定
EnableSendfile Off
EnableMMAP Off
另外,当Log有出现AcceptEx failed相关错误时,建议调整以下设定
AcceptFilter http none
#AcceptFilter https none 这行apache 2.4.1设了就不能连443了,所以我没设定,在apache 2.4.3版可正常运作
bug修正相关文件: http://www.apachelounge.com/viewtopic.php?p=22306
指令说明http://httpd.apache.org/docs/2.4/mod/core.html#acceptfilter
备注: Win32DisableAcceptEx 指令在apache2.4 被AcceptFilter None 取代
相关参考文章:
http://www.neo.com.tw/archives/000223
http://www.iteye.com/news/24881
http://www.apachelounge.com/viewtopic.php?t=4450
6. Listen 的设定调整
以443为例,不可以只设定Listen 443
会出现以下错误
(OS 10048)一次只能用一个通讯端位址(通讯协定/网路位址/连接埠)。: AH00072: make_sock: could not bind to address [::]:443
(OS 10048)一次只能用一个通讯端位址(通讯协定/网路位址/连接埠)。: AH00072: make_sock: could not bind to address 0.0.0.0:443
AH00451: no listening sockets available, shutting down
AH00015: Unable to open logs
因此需指定监听的IP ,可设定多个
例如:
Listen 192.168.2.1:443
Listen 127.0.0.1:443
其他异常BUG :
某天突然心血来潮测试了一下可不可以开启.htaccess的档案,很惊恐的居然可以开启冏
原本httpd.conf 预设不可开启.ht* 的设定失效!
<Files ".ht*">
Require all denied
</Files>
测试的结果,httpd.conf里的<Files>跟<FilesMatch>完全失效!
不确定跟<VirtualHost> 设定有没有关系( 其实我跟httpd.conf 没这么熟,我都是被刀抵着脖子的=..=a )
经过半天的折磨,最后发现改用LocationMatch设定还勉强行得通
因为我没有用到htpasswd ,所以比较不怕.ht* 的档案被开启....所以就先用这种跛脚的方式解决了.....
例如:
<LocationMatch "\.svn">
Require all denied
</LocationMatch>
注意:子阶层的LocationMatch设定,指令要设在母阶层的行数之下,不然会被覆盖
且不可以对" .ht* "设定 !!
因为Server 就无法读取.ht* 的资料...当然里面的设定就不能跑了
另外就是.htaccess中,<Files>跟<FilesMatch> 可能会失效
而且.htaccess 里无法设定LocationMatch .........(叹气)
在我的环境中,Server 2008 的.htaccess 有生效,
但是在Win7 环境中,放在第二层资料夹的.htaccess 有生效,若第三层资料夹才放.htaccess 就会失效
总之一整个诡异...只好先当作BUG 看待
文章转载页面:http://www.dotblogs.com.tw/maplenote/archive/2012/07/20/apache24_httpd_conf.aspx