Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3036029
  • 博文数量: 535
  • 博客积分: 15788
  • 博客等级: 上将
  • 技术积分: 6507
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-07 09:11
文章分类

全部博文(535)

文章存档

2016年(1)

2015年(1)

2014年(10)

2013年(26)

2012年(43)

2011年(86)

2010年(76)

2009年(136)

2008年(97)

2007年(59)

分类:

2008-01-14 11:44:03


设置环境变量
SetEnv env-variable value

根据客户端请求属性设置环境变量
SetEnvIf attribute regex [!]env-variable[=value] [[!]env-variable[=value]] ...
server config, virtual host, directory, .htaccess

SetEnvIf指令根据客户端的请求属性设置环境变量。第一个参数attribute必须是下列三种类别之一:

  1. 一个HTTP请求头域(参见);例如:Host, User-Agent, Referer, Accept-Language 。可以用一个正则表达式来进行匹配。
  2. 下列请求属性之一:
    • Remote_Host 远程主机名(若可用)
    • Remote_Addr 远程主机IP地址
    • Server_Addr 接收到请求的服务器IP地址(2.0.43及以后版本)
    • Request_Method 所用的请求方法(GET, POST等等)
    • Request_Protocol 请求所使用的协议及其版本("HTTP/0.9", "HTTP/1.0", "HTTP/1.1"等)
    • Request_URI 在HTTP请求行中请求的资源(通常是URL中去除协议、主机以及查询字符串后剩余的部分)。
  3. 列出的与该请求关联的环境变量名字中的一个。这将允许SetEnvIf指令基于预先匹配的结果进行测试。只有那些由较早的SetEnvIf[NoCase]指令定义的环境变量才可以按照这种方式测试。"较早的"意思是它们在更上层的作用域(比如全局范围)中被定义或者在同一作用域中较早出现。只有在请求的属性未能得到匹配并且attribute没有使用正则表达式的时候,环境变量才会被考虑。

如:不记录192.168.7.139的访问日志
首先设置环境变量 SetEnvIf Remote_Addr "192\.168\.7\.139" dontlog
使用上面设置的环境变量
CustomLog "logs/access_log" common env=!dontlog





SetEnvIfNoCase
说明: Sets environment variables based on attributes of the request without respect to case
语法: SetEnvIfNoCase attribute regex [!]env-variable[=value] [[!]env-variable[=value]] ...
上下文: 服务器配置, 虚拟主机, 目录, .htaccess
覆盖项: FileInfo
状态: Base
模块: mod_setenvif
兼容性: Apache 1.3 and above

The SetEnvIfNoCase is semantically identical to the SetEnvIf directive, and differs only in that the regular expression matching is performed in a case-insensitive manner. For example:
SetEnvIfNoCase Host Apache\.Org site=apache
This will cause the site environment variable to be set to "apache" if the HTTP request header field Host: was included and contained Apache.Org, apache.org, or any other combination.
 
SetEnvIfNoCase 当满足某个条件时,为变量赋值,一般结合其他指令使用。
如:
1。SetEnvIf Request_URI "/logo(.)+" local_ref=0
Allow from env=local_ref  当local_ref有值时,可以访问。
2。SetEnvIfNoCase Request_URI .js$ useless-file
CustomLog logs/hebgc.com/access.log combined env=!useless-file
当满足条件时才记录日志。
 
 
阅读(3976) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~