- 浏览: 1332519 次
- 性别:
- 来自: 合肥
文章分类
- 全部博客 (404)
- ToDoList (24)
- 项目管理 (39)
- REDMINE (1)
- Oracle (32)
- 杂文 (21)
- 管理 (19)
- Java (6)
- 全文搜索 (1)
- 编程语言排名 (4)
- 人力资源 (5)
- SVN (1)
- CMMI (2)
- VER (1)
- VAL (1)
- 其他 (8)
- OceanBase (1)
- IT PRO (2)
- KVM (1)
- Access (1)
- Drupal (3)
- mysql (4)
- 理财 (1)
- 读书笔记 (6)
- 个人总结 (16)
- 我的推荐 (13)
- REDMINE培训材料 (0)
- 随笔 (10)
- AIX (1)
- 管理故事 (12)
- 工具推荐 (6)
- 系统架构 (5)
- 免费活动 (3)
- 名词解释 (3)
- Apache (5)
- mongrel (4)
- redmine插件 (0)
- 知识管理 (4)
- REDMINE第三方应用 (5)
- redmine问题 (0)
- NOSQL (1)
- UML (1)
- SQLite (1)
- use case,UML (1)
- nginx (5)
- 规划 (1)
- 系统思考 (1)
- resin (2)
- android (43)
- android代码 (10)
- HTML5 (1)
- 移动开发 (4)
- android问题 (3)
- DB2 (4)
- http (1)
- LBS (1)
- IT职业规划 (11)
- 微信 (1)
- 就业 (1)
- google (2)
- 微信开发 (2)
- js (1)
- Anroid (1)
- Service Worker (1)
- weblogic (2)
- 测试 (1)
- weblogi (1)
- vue (4)
- jeeplus (1)
- ureport (1)
最新评论
-
Caelebs:
上海交大?ms工作六年?感觉好屌啊我厂一堆10K 20K 98 ...
IT人为什么难以拿到高薪? -
小桔子:
如果加入listView 在滑动的时候偶尔会空指针异常,加入P ...
Android组件推荐-侧滑效果DragLayout -
wangyonglin1123:
小公司是锻炼人的 不管是业务技术都会有突飞猛进的进度 进步 ...
程序员在大公司工作好?还是在小公司工作?我的经历和建议[ZT] -
wangyonglin1123:
必须有所专长 技术和业务都需要 你必须在一个行业够牛逼
程序员的出路之一,拥有一技之长、打造自己的精品、更广阔的市场【ZT】 -
luhuajcdd:
这个不错
StarUML 不能在64位的windows7下运行,提示错误的解决方案
apache httpd.conf 中SetEnvIf and SetEnvIfNoCase Examples
- 博客分类:
- Apache
Htaccess SetEnvIf and SetEnvIfNoCase Examples
Contents
- Unique mod_setenvif Variables
- Populates HTTP_MY_ Variables with mod_setenvif variable values
- Set REMOTE_HOST to HTTP_HOST
- Allows only if HOST Header is present in request
- Add values from HTTP Headers
- Set the REDIRECT_STATUS for Interpreter Security
- Block Bad Bots
- Allow Search robots
- SetEnvIf Directive
- htaccess Guide Sections
SetEnvIf and SetEnvIfNoCase are really useful directives supplied by the mod_setenvif module that allow you to conditionally set environment variables accessible by scripts and apache based on the value of HTTP Headers, Other Variables, and Request information.
For debugging, you may want to use my server environment variable debugging script
- Unique mod_setenvif Variables
- Populates HTTP_MY_ Variables with mod_setenvif variable values
- Set REMOTE_HOST to HTTP_HOST
- Allows only if HOST Header is present in request
- Add values from HTTP Headers
- Set the REDIRECT_STATUS for Interpreter Security
Unique mod_setenvif Variables
These can be used for attribute
.
crawl-66-249-70-24.googlebot.com
66.249.70.24
208.113.183.103
GET
HTTP/1.1
/robots.txt
Syntax:
SetEnvIf attribute regex [!]env-variable[=value] [[!]env-variable[=value]] ...
Populates HTTP_MY_ Variables with mod_setenvif variable values
SetEnvIfNoCase Remote_Host "(.*)" HTTP_MY_REMOTE_HOST=$1 SetEnvIfNoCase Remote_Addr "(.*)" HTTP_MY_REMOTE_ADDR=$1 SetEnvIfNoCase Server_Addr "(.*)" HTTP_MY_SERVER_ADDR=$1 SetEnvIfNoCase Request_Method "(.*)" HTTP_MY_REQUEST_METHOD=$1 SetEnvIfNoCase Request_Protocol "(.*)" HTTP_MY_REQUEST_PROTOCOL=$1 SetEnvIfNoCase Request_URI "(.*)" HTTP_MY_REQUEST_URI=$1
Set REMOTE_HOST to HTTP_HOST
Sets REMOTE_HOST to www.askapache.com if Remote_Addr=208.113.183.103. This can be useful if your server doesn't automatically do a reverse lookup on a remote address, so this way you can tell if the request was internal/from your server.
SetEnvIf Remote_Addr 208\.113\.183\.103 REMOTE_HOST=www.askapache.com
Allows only if HOST Header is present in request
SetEnvIfNoCase ^HOST$ .+ HTTP_MY_HAS_HOST Order Deny,Allow Deny from All Allow from env=HTTP_MY_HAS_HOST
or
SetEnvIfNoCase Host .+ HTTP_MY_HAS_HOST Order Deny,Allow Deny from All Allow from env=HTTP_MY_HAS_HOST
Add values from HTTP Headers
SetEnvIfNoCase ^If-Modified-Since$ "(.+)" HTTP_IF_MODIFIED_SINCE=$1 SetEnvIfNoCase ^If-None-Match$ "(.+)" HTTP_IF_NONE_MATCH=$1 SetEnvIfNoCase ^Cache-Control$ "(.+)" HTTP_CACHE_CONTROL=$1 SetEnvIfNoCase ^Connection$ "(.+)" HTTP_CONNECTION=$1 SetEnvIfNoCase ^Keep-Alive$ "(.+)" HTTP_KEEP_ALIVE=$1 SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1 SetEnvIfNoCase ^Cookie$ "(.+)" HTTP_MY_COOKIE=$1
Set the REDIRECT_STATUS for Interpreter Security
This is useful in disallowing direct access to interpreters like shell scripts, cgi scripts, and other interpreters. Only works this way if you have a static IP for your server. So the only way to access these files is by instructing the server itself to request the file, using an Action directive or by requesting the file through a .php or other script using curl or wget, or something like fsockopen.
<filesMatch "\.(cgi|sh|pl)$"> SetEnvIfNoCase Remote_Addr 208\.113\.183\.103 REDIRECT_STATUS Order Deny,Allow Deny from All Allow from env=REDIRECT_STATUS </filesMatch>
Block Bad Bots
Can be useful if your site is getting hammered by spambots. Some nice examples from around the net are at Fight Blog Spam With Apache ... Keep in mind the HTTP_USER_AGENT is directly from the client, so its easy to spoof / change. Instead use mod_security for a much better solution.
SetEnvIfNoCase User-Agent "^Bandit" bad_bot SetEnvIfNoCase User-Agent "^Baiduspider" bad_bot SetEnvIfNoCase User-Agent "^BatchFTP" bad_bot SetEnvIfNoCase User-Agent "^Bigfoot" bad_bot SetEnvIfNoCase User-Agent "^Black.Hole" bad_bot Order Allow,Deny Allow from All Deny from env=bad_bot
Allow Search robots
This does the opposite of above, allowing ONLY these web robots access. Other than rogue robots, configuring your robots.txt file correctly will keep most robots where you want them.
SetEnvIfNoCase User-Agent .*google.* search_robot SetEnvIfNoCase User-Agent .*yahoo.* search_robot SetEnvIfNoCase User-Agent .*bot.* search_robot SetEnvIfNoCase User-Agent .*ask.* search_robot Order Deny,Allow Deny from All Allow from env=search_robot
SetEnvIf Directive
Sets environment variables based on attributes of the request |
SetEnvIf attribute regex [!]env-variable[=value] [[!]env-variable[=value]] ...
|
server config, virtual host, directory, .htaccess |
FileInfo |
Base |
mod_setenvif |
The SetEnvIf
directive defines environment variables
based on attributes of the request. The attribute specified in the first
argument can be one of three things:
- An HTTP request header field (see RFC2616
for more information about these); for example:
Host
,User-Agent
,Referer
, andAccept-Language
. A regular expression may be used to specify a set of request headers. - One of the following aspects of the request:
-
Remote_Host
- the hostname (if available) of the client making the request -
Remote_Addr
- the IP address of the client making the request -
Server_Addr
- the IP address of the server on which the request was received (only with versions later than 2.0.43) -
Request_Method
- the name of the method being used (GET
,POST
, et cetera) -
Request_Protocol
- the name and version of the protocol with which the request was made (e.g., "HTTP/0.9", "HTTP/1.1", etc.) -
Request_URI
- the resource requested on the HTTP request line -- generally the portion of the URL following the scheme and host portion without the query string. See theRewriteCond
directive ofmod_rewrite
for extra information on how to match your query string.
-
- The name of an environment variable in the list of those associated with the request. This allows
SetEnvIf
directives to test against the result of prior matches. Only those environment variables defined by earlierSetEnvIf[NoCase]
directives are available for testing in this manner. 'Earlier' means that they were defined at a broader scope (such as server-wide) or previously in the current directive's scope. Environment variables will be considered only if there was no match among request characteristics and a regular expression was not used for the attribute.
The second argument (regex) is a regular expression. If the regex matches against the attribute, then the remainder of the arguments are evaluated.
The rest of the arguments give the names of variables to set, and optionally values to which they should be set. These take the form of
-
varname
-
!varname
-
varname=value
In the first form, the value will be set to "1". The second will
remove the given variable if already defined, and the third will set the
variable to the literal value given by value
. Since version 2.0.51
Apache will recognize occurrences of $1
..$9
within value
and replace them by parenthesized subexpressions of regex
.
SetEnvIf Example:
SetEnvIf Request_URI "\.gif$" object_is_image=gif SetEnvIf Request_URI "\.jpg$" object_is_image=jpg SetEnvIf Request_URI "\.xbm$" object_is_image=xbm SetEnvIf Referer www\.askapache\.com intra_site_referral SetEnvIf object_is_image xbm XBIT_PROCESSING=1 SetEnvIf ^SETENVIF* ^[a-z].* HAS_SETENVIF
The first three will set the environment variable object_is_image
if the request was for an image file, and the fourth sets intra_site_referral
if the referring page was somewhere on the www.askapache.com
Web site.
The last example will set environment variable HAS_SETENVIF
if the request contains any headers that begin with "SETENVIF" whose values begins with any character in the set [a-z].
htaccess Guide Sections
- htaccess tricks for Webmasters
- HTTP Header control with htaccess
- PHP on Apache tips and tricks
- SEO Redirects without mod_rewrite
- mod_rewrite examples, tips, and tricks
- HTTP Caching and Site Speedups
- Authentication on Apache
- htaccess Security Tricks and Tips
- SSL tips and examples
- Variable Fun (mod_env) Section
- .htaccess Security with MOD_SECURITY
- SetEnvIf and SetEnvIfNoCase Examples
from:http://www.askapache.com/htaccess/setenvif.html
发表评论
-
apache [error] (OS 10061)解决方案
2012-04-27 14:49 9680使用apache+mongrel_cluster发布redmi ... -
apache,Process exiting because it reached MaxRequestsPerChild. Signaling the par
2012-04-16 15:56 5312使用redmine之后,查看apache的日志发现大量的一下提 ... -
apache实现企业自定义二级域名管理-mod_rewrite
2012-03-28 14:37 3024目的 最近公司在做电子商务网站,需要做各个企业的电子商 ... -
apache错误那位可以帮忙解决下-Invalid URI in request \x13BitTorrent protocolex
2012-03-02 14:17 692错误日志 redmine服务器,采用apache服务器作为前 ... -
Apache Error Code 错误内部码以及说明
2012-02-15 13:33 2117Apache Error Code 错误内部码以及说明(转载) ... -
apache的Client denied by server configuration错误处理
2012-02-15 12:01 10187今天在调整redmine的 部署,因为每天下午5点左右,因为人 ...
相关推荐
apache httpd.conf中文 apache优化
了解并熟练掌握httpd.conf文件中的常用指令对于管理和优化Apache服务器至关重要。以下是一些主要的指令及其解释: 1. **ServerRoot**: 这个指令指定Apache服务器的根目录,即包含所有配置文件、模块和日志文件的...
### Apache的httpd.conf配置详解 #### 一、概述 `httpd.conf` 是Apache Web服务器的核心配置文件,它控制着服务器的行为与功能。通过合理地配置这些参数,可以极大地提高服务器的安全性、性能和可扩展性。下面将对...
根据给定的文件标题、描述、标签以及部分内容,本文将详细介绍Apache2的`httpd.conf`配置文件中的关键知识点。 ### Apache2 httpd.conf 文件概述 `httpd.conf`是Apache HTTP服务器的主要配置文件,它控制着服务器...
apache2配置文件httpd.conf
### Apache的httpd.conf文件配置详解 #### 一、引言 `httpd.conf`是Apache Web服务器的核心配置文件,它决定了服务器的行为、性能及功能。对于系统管理员来说,掌握如何正确配置`httpd.conf`至关重要。本文将详细...
根据提供的文件信息,我们可以深入解析`httpd.conf`配置文件中的关键设置与参数。这份文档主要涉及Apache服务器的配置选项,对于理解如何调整和优化Apache服务具有重要意义。 ### ServerRoot `ServerRoot`用于指定...
Notepad++ 自定义 httpd.conf 文件语法高亮的配置文件 使用方法: http://blog.csdn.net/zhyl8157121/article/details/51320819
本文将深入解析 `httpd.conf` 中的关键配置项,并解释它们的功能与作用。 #### 二、主要配置部分 `httpd.conf` 主要分为三个部分: 1. **全局环境配置 (Global Environment)** 2. **主服务器配置 ('Main' server ...
django整合后的apache httpd.conf
Apache2 httpd.conf配置文件中文版详解 # 基于 NCSA 服务的配置文件。
通过以上详细介绍,我们可以看到 `httpd.conf` 配置文件中的各项参数是如何定义和影响 Apache 服务器的行为与特性的。正确配置这些参数对于实现高效的 Web 服务至关重要。希望本文能为初学者提供一定的帮助,并为...
httpd.conf是Apache服务器的主要配置文件,它定义了服务器的行为、监听端口、虚拟主机、文档根目录、日志文件位置等核心参数。以下是一些关键配置项的解释: 1. **ServerRoot**: 指定Apache安装的根目录,通常设置...
这个文件位于Apache软件安装的根目录下,通常命名为httpd.conf或apache2.conf,根据不同的操作系统和安装方法可能会有所不同。配置文件的修改直接影响到服务器的运行方式和性能。 1. **基本配置** - `ServerRoot`...
apche httpd.conf找不到,就直接下载使用在这个文件,httpd.conf 配置文件
httpd.conf的中文版本,英文不好的朋友可以参考