在这里让我们一起学习,一起提高!
本示例将避免对图片的请求出现在访问日志中。 你可以随便改改就将它用于避免特定目录或特定主机的请求被记入日志。


SetEnvIf Request_URI \.gif image-request
SetEnvIf Request_URI \.jpg image-request
SetEnvIf Request_URI \.png image-request
CustomLog logs/access_log common env=!image-request

只记录php访问记录的设置

SetEnvIf Request_URI "^/.*\.php$" dontlog
CustomLog logs/access_log common env=dontlog



SetEnvIf Remote_Addr "127\.0\.0\.1" dontlog
SetEnvIf Request_URI "^/favicon.ico$" dontlog
SetEnvIf Request_URI "^/images/.*$" dontlog
SetEnvIf Request_URI "^/.*\.js$" dontlog
SetEnvIf Request_URI "^/.*\.css$" dontlog
SetEnvIf Request_URI "^/.*\.dwr$" dontlog


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~VirtualHost~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

NameVirtualHost 192.168.1.103:80


<VirtualHost 192.168.1.103:80>
    ProxyRequests On
    DocumentRoot /opt/project

    ServerName 192.168.1.103
    DirectoryIndex index.jsp
    
    RewriteEngine On
    RewriteRule ^(http|https)://.* - [F]
    
    ProxyPass /pic/ http://192.168.1.101/
    ProxyPass /report/ http://192.168.1.101:8081/report/
    ProxyPass / balancer://proxy/ stickysession=JSESSIONID
    <Proxy balancer://proxy>
          BalancerMember ajp://192.168.1.103:10003/  route=A loadfactor=1
          BalancerMember ajp://192.168.1.103:20003/  route=B loadfactor=1
          BalancerMember ajp://192.168.1.101:10003/  route=C loadfactor=1
          BalancerMember ajp://192.168.1.101:20003/  route=D loadfactor=1
    </Proxy>
    ErrorLog logs/error_log.log
    CustomLog "|/usr/local/httpd/bin/rotatelogs /usr/local/httpd/logs/access_%Y_%m_%d.log 86400 480" combined env=!dontlog
</VirtualHost>



语法SetEnv env-variable value  


语法SetEnvIf attribute regex [!]env-variable[=value] [[!]env-variable[=value]] ...  


SetEnvIf指令根据客户端的请求属性设置环境变量。第一个参数attribute必须是下列三种类别之一:
一个HTTP请求头域(参见RFC2616);例如:Host, User-Agent, Referer, Accept-Language 。可以用一个正则表达式来进行匹配。下列请求属性之一: 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中去除协议、主机以及查询字符串后剩余的部分)。列出的与该请求关联的环境变量名字中的一个。这将允许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:
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有值时,可以访问。
当满足条件时才记录日志。

分页: 1/1 第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]