不推荐使用Apache AddOutputFilterByType.如何使用mod_filter重写?

Ian*_*Ian 13 apache

Apache中不推荐使用AddOutputFilterByType.

文档说明使用mod_filter可以使用相同的功能.

我目前正在使用

AddOutputFilterByType DEFLATE text/html
Run Code Online (Sandbox Code Playgroud)

使用mod_filter的等价物是什么?

Tom*_*zky 16

AddOutputFilterByType有严重的限制httpd-2.2因此它被标记为已弃用.但是在httpd-2.4这个指令中被移动filter_module,纠正和取消了.

在Apache 2.2的则应该启用filter_moduledeflate_module与使用:

# Declare a "gzip" filter, it should run after all internal filters like PHP or SSI
FilterDeclare  gzip CONTENT_SET

# "gzip" filter can change "Content-Length", can not be used with range requests
FilterProtocol gzip change=yes;byteranges=no

# Enable "gzip" filter if "Content-Type" contains "text/html", "text/css" etc.
FilterProvider gzip DEFLATE resp=Content-Type $text/html
FilterProvider gzip DEFLATE resp=Content-Type $text/css
FilterProvider gzip DEFLATE resp=Content-Type $text/javascript
FilterProvider gzip DEFLATE resp=Content-Type $application/javascript
FilterProvider gzip DEFLATE resp=Content-Type $application/x-javascript

# Add "gzip" filter to the chain of filters
FilterChain    gzip
Run Code Online (Sandbox Code Playgroud)

deflate_module只会向声明支持gzip请求标头中的编码的浏览器提供压缩内容.


T.T*_*dua 6

它在 Apache 2.3.7 中不再被弃用,因为它被移动/集成到mod_filter. 所以,我得到了什么:

代替:

<IfModule mod_deflate.c> 
   AddOutputFilterByType DEFLATE text/css
Run Code Online (Sandbox Code Playgroud)

使用:

<IfModule mod_filter.c>
...
Run Code Online (Sandbox Code Playgroud)


小智 5

我用mod_filter替代而不是放气,但是想法是一样的。这是对我有用的方法(我正在做反向代理并重写URL和链接):

LoadModule substitute_module modules/mod_substitute.so
LoadModule filter_module modules/mod_filter.so

FilterDeclare MYFILTER
# syntax changed in Apache2.4  (see also  https://httpd.apache.org/docs/current/mod/mod_filter.html)  
FilterProvider MYFILTER SUBSTITUTE "%{Content_Type} = 'text/html'"
FilterProvider MYFILTER SUBSTITUTE "%{Content_Type} = 'text/xml'"
FilterProvider MYFILTER SUBSTITUTE "%{Content_Type} = 'application/javascript'"
FilterProvider MYFILTER SUBSTITUTE "%{Content_Type} = 'application/json'"

<Location /sial/> 
  ProxyPass        http://localhost:8300/
  ProxyPassReverse http://localhost:8300/
  ProxyPassReverseCookiePath / /sial/  
  FilterChain MYFILTER
  Substitute "s|/tea_sial_v2|/sial/tea_sial_v2|inq"
</Location>
Run Code Online (Sandbox Code Playgroud)