HTTP Error 500.52 (gzip compression) when using IIS as a reverse proxy

When you want to run multiple web servers on port 80 and one of them is IIS, you can use URL rewriting to setup IIS as a reverse proxy. That's easy enough, you just configure the other web server to listen on a different port (e.g. 8080). Then you add a new rewrite rule in IIS, select reserve proxy and enter the external (port 80) and the internal (8080) and you're done.

However, you might run into an issue if the web server uses compression, as IIS will not be able to rewrite the compressed response:

HTTP Error 500.52 - URL Rewrite Module Error.
Outbound rewrite rules cannot be applied when the content of the HTTP response is encoded ("gzip").

If you can disable compression, problem solved.

But maybe you cannot disable it (or don't know how). I had this issue with Octopus deploy. Maybe there is a hidden config switch to disable compression, but I didn't see any. In this case you can use the IIS rewrite rule to override the HTTPACCEPTENCODING header before the request is delegated to the other web server.

There are only two smaller hurdles on the way.
  • The IIS Manager UI won't let you set an empty value for the header, so you have to edit it in the web.config
  • By default, you're not allowed to set the HTTP_ACCEPT_ENCODING header, so you have to allow it. This can be done in the "Allowed Server Variables" menu, which you'll find in the side bar of the "URL Rewrite" feature ("View Server Variables...")

Without the HTTP_ACCEPT_ENCODING header allowing compressed responses, the web server should not use gzip compression and the rewrite should work just fine.
comments powered by Disqus