问题
I'm trying to configure a reverse proxy from Apache web server (A) to another Apache web server on different machine (B).
With configuration I'm currently using I'm able to access web page located on server B as if it were on server A, however requests for some assets constantly result in ERR_CONTENT_DECODING_FAILED (at least in chrome). This doesn't happen when I'm using simple redirection instead of proxying.
I have browsed through request and response headers and it seems that everything went fine with file transferring:
Request:
GET /app1/assets/css/vendor.min.css?1470017050 HTTP/1.1
Host: some.host.address
...
Accept: text/css,*/*;q=0.1
Accept-Encoding: gzip, deflate, sdch
Response:
HTTP/1.1 200 OK
...
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Type: text/css;charset=utf-8
Connection: Keep-Alive
Transfer-Encoding: chunked
I used below configuration on server A:
ProxyPreserveHost on
ProxyPass "/app1/" "http://some.host.address:8080/app1/"
ProxyPassReverse "/app1/" "some.host.address:8080/app1/"
ProxyHTMLURLMap "http://some.host.address:8080" "/app1"
<Location /app1/>
ProxyPassReverse /app1/
ProxyHTMLEnable On
ProxyHTMLURLMap / /app1/
</Location>
回答1:
The ERR_CONTENT_DECODING_FAILED error occurs when the back-end server uses compression and the proxy server doesn't handle deflated content during rewriting.
I found useful information in this wiki and also in the mod_proxy_html documentation.
I tried the following with success (inflate before rewriting):
ProxyHTMLEnable On
SetOutputFilter INFLATE;proxy-html;DEFLATE
ProxyHTMLURLMap / /app1/
Then after reading a (now removed) comment on the mod_proxy_html page, I modified to this (should handle character encoding correctly):
ProxyHTMLEnable On
RequestHeader unset Accept-Encoding
ProxyHTMLCharsetOut *
ProxyHTMLURLMap / /app1/
ProxyHTMLURLMap /app1/ /app1/
来源:https://stackoverflow.com/questions/40683850/apache-proxying-leads-to-err-content-decoding-failed-error