Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Proxying leads to ERR_CONTENT_DECODING_FAILED error

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>
like image 443
senx Avatar asked Nov 18 '16 18:11

senx


People also ask

What is Err_content_decoding_failed?

The error “ERR_CONTENT_DECODING_FAILED” is seen on almost all browsers. Sometimes, it pops up while loading a particular website but it can also start appearing when you migrate to a new server. This error persists even after refreshing the page a couple of times.

Can I use Apache as reverse proxy?

In addition to being a "basic" web server, and providing static and dynamic content to end-users, Apache httpd (as well as most other web servers) can also act as a reverse proxy server, also-known-as a "gateway" server.

What is ProxyPass and ProxyPassReverse?

ProxyPassReverse will intercept those headers, and rewrite them to match the Apache proxy server. ProxyPass will create a reverse proxy. A reverse proxy (or gateway), appears to the client just like an ordinary web server.

How does Apache support proxy?

The Apache reverse proxy handles the incoming request, recognizes that an Apache ProxyPassReverse setting exists, and then forwards the request to Tomcat. Then Tomcat handles the request, returns a response to the Apache reverse proxy, and Apache returns the response to the client.


1 Answers

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/
like image 199
Ábel Hegedüs Avatar answered Oct 18 '22 06:10

Ábel Hegedüs