`
xinglongbing
  • 浏览: 146607 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

关于Apache RewriteRule和ProxyPass*指令的差别

 
阅读更多

Apache RewriteRule [P]和ProxyPass(ProxyPassMatch)指令的差别:

虽然都可以用来做代理转发,但是两者还是有不少细微的差别:

1.RewriteRule可以对URL重写可以实现更加灵活的处理;

2.ProxyPass*对重写能有更高的性能。在apache官方文档2.2版本中没有给出RewriteRule [P]详细说明,而2.4版本文档有更加具体的使用说明。主要是没法提供连接池从而实现多个Http请求复用TCP链接达到性能上的提升。具体可以用tcpdump或wireshark进行验证。

还需要注意一点是:如果使用

SetEnv force-proxy-request-1.0 1

SetEnv proxy-nokeepalive 1 

这两个指令也会导致没法使用keepalive connection。

 

系统环境:Redhat + Apache2.2.15 + Php

原因:

     论坛服务器上发现大量TIME_WAIT状态的tcp链接(600-900),上服务器上netstat发现都是跟frontend服务器之间的链接。大量这种状态的链接还是消耗不少资源(主要是端口和内存),因此想办法降低。

      frontend服务器大量使用RewriteRule对进行做代理转发,怀疑这个代理转发的动作没有复用tcp链接。通过tcpdump证实了这种想法,每个请求进来都是有tcp链接建立和断开的过程。httpd.apache.org中2.2版本文档仔细看了下RewriteRule P指令的说明好像没有讲到具体的信息。后来又跑到2.4版本中去看了下发现如下说明。调整frontend指令以后TIME_WAIT维持在100左右,而且大部分都是到Mysql的链接了。

 

   

P|proxy

Use of the [P] flag causes the request to be handled by mod_proxy, and handled via a proxy request. For example, if you wanted all image requests to be handled by a back-end image server, you might do something like the following:

RewriteRule /(.*)\.(jpg|gif|png)$ http://images.example.com/$1.$2 [P]

Use of the [P] flag implies [L] - that is, the request is immediately pushed through the proxy, and any following rules will not be considered.

You must make sure that the substitution string is a valid URI (typically starting with http://hostname) which can be handled by the mod_proxy. If not, you will get an error from the proxy module. Use this flag to achieve a more powerful implementation of the ProxyPass directive, to map remote content into the namespace of the local server.

Security Warning

Take care when constructing the target URL of the rule, considering the security impact from allowing the client influence over the set of URLs to which your server will act as a proxy. Ensure that the scheme and hostname part of the URL is either fixed, or does not allow the client undue influence.

Performance warning

Using this flag triggers the use of mod_proxy, without handling of persistent connections. This means the performance of your proxy will be better if you set it up withProxyPass or ProxyPassMatch

This is because this flag triggers the use of the default worker, which does not handle connection pooling.

Avoid using this flag and prefer those directives, whenever you can.

Note: mod_proxy must be enabled in order to use this flag.

分享到:
评论

相关推荐

    关于Apache_mod_rewite的中文配置和RewriteRule规则详细介绍

    关于Apache_mod_rewite的中文配置和RewriteRule规则详细介绍

    Apache之Rewrite和RewriteRule规则梳理以及http强转https的配置总结(完整版)

    本篇文章详细介绍了Apache之Rewrite和RewriteRule规则以及http强转https的配置总结,可作为平时运维手册.特此分享,希望能帮助到有用到的朋友!

    APACHE_RewriteRule

    APACHE_RewriteRule详细说明

    Apache2.2 初级URL重写指南(RewriteRule)

    对Apache的URL重定向指令RewriteRule进行了详细的介绍。

    淘宝帝国 淘宝客 6.3最新版本

    淘宝帝国 淘宝客 6.3最新版本# Helicon ISAPI_Rewrite configuration file # Version 3.1.0.56 ... RewriteEngine On ... ... RewriteRule ^(.*)taoshop/(.+)$ $1... RewriteRule ^(.*)59b2c-([0-9]+)/(.+)$ $1img/nopic.gif

    Apache2.4 Win64位

    apache No input filespecified,今天是我们配置apache RewriteRule时出现这种问题,解决办法很简单如下 打开.htaccess 在RewriteRule 后面的index.php教程后面添加一个“?” 完整代码如下 .htaccess ...

    apache rewrite rule

    apache rewrite rule: 介绍详细

    浅谈PHP各环境下的伪静态配置

    一、Apache的伪静态配置 1、网站根目录下需要有 .htaccess 文件,没有则自己创建一个,内容 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ ...

    配置apache默认使用ssl的方法

    然后在下面添加,具体位置似乎没有大的关系,可以自行测试一下: 代码如下:RewriteEngine On RewriteRule /.* https://www.example.com/ [R] 替换URL为你需要的就好了。看到其它地方还添加了其他的选项,我这里就...

    个人博客系统源码 雪落.溯雪Sxlog轻博客源码 PHP开源 简洁干净轻博客源码.zip

    以下提供了Nginx和Apache环境的伪静态设置。 伪静态设置 Nginx环境: if (!-d $request_filename){ set $rule_0 1$rule_0; } if (!-f $request_filename){ set $rule_0 2$rule_0; } if ($rule_0 = “21”){ rewrite ...

    Apache实现禁止中文浏览器访问与301重定向的方法

    部署禁止中文浏览器访问网站 在网站的根目录中的 htaccess 文件中,增加如下语句   ############################################ ## enable rewrites ...RewriteRule ^.*$ http://www.baidu.com [R=302

    apache反向代理

    ④“RewriteEngine on”一行用来启动Apache修改响应数据包的功能,否则下面的“RewriteCond”和“RewriteRule”将不起作用。 6.添加记录进入/etc/hosts文件 在上面的虚拟主机重写规则中,重写后的URL与您所请求...

    Apache服务器关闭TRACE Method请求方式的方法

    TRACE和TRACK是用来调试web服务器连接的HTTP方式。支持该方式的服务器存在跨站脚本漏洞,通常在描述各种浏览器缺陷的时候,把”Cross-Site-Tracing”...•服务器用户在httpd.conf尾部添加如下指令后重启apache即可: Tr

    apache_rewrite_tester:为你的 apache 重写规则编写单元测试,brah

    apache_rewrite_tester 为您的 Apache 重写规则编写单元测试,呵呵。 这显然只是一个徒劳的练习,但它恰好是一个非常有教育意义的徒劳练习。 不要指望这与 Apache 的任何特质相匹配。

    Apache使用 .htaccess 来实现强制https访问的方法

    我们可以用Apache的.htaccess的重定向规则来实现http强制跳转到https访问网站。( 重要提示:必须将代码放到.htaccess文件内容的最前面,以保证重定向优先权。) 代码如下: RewriteEngine On RewriteCond %{SERVER_...

    apache中伪静态配置和使用(Apache虚拟主机下Discuz伪静态)

    一 打开 Apache 的配置文件 httpd.conf 。 二 将#LoadModule rewrite_module modules/mod_rewrite前面的#去掉 三 在 httpd.conf中添加: <IfModule> RewriteEngine On #RewriteCond %{ENV:SCRIPT_URL} (?:index|...

    Apache中301重定向的配置代码

    新建.htaccess文件,输入下列内容(需要开启mod_rewrite): 1)将不带WWW的域名转向到带WWW的域名下 代码如下: Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} ^jb51.net [NC] RewriteRule ^...

    网站常见漏洞及解决办法

    ①开启Apache 的mod_rewrite功能: 在Apahce的配置文件httpd.conf中把#LoadModule rewrite_module modules/mod_rewrite.so前的#去掉 在httpd.conf中找到下面这段 <Directory />Options FollowSymLinks ...

    Apache RewriteBase 指令使用介绍

    在下文中,你可以看见RewriteRule可以用于目录级的配置文件中 (.htaccess)并在局部范围内起作用,即规则实际处理的只是剥离了本地路径前缀的一部分。处理结束后,这个路径会被自动地附着回去。默认值 是”...

    详解no input file specified 三种解决方法

    一.IIS Noinput file specified ... 方法二: ... 找到 ... cgi.force_redirect = 1 ...apache No input filespecified,今天是我们配置apache RewriteRule时出现这种问题,解决办法很简单如下 打开.htaccess 在RewriteRule

Global site tag (gtag.js) - Google Analytics