Iis – Apache Reverse Proxy IIS Streaming File

apache-2.2iisreverse-proxy

We recently setup an apache reverse proxy with IIS sitting behind it. All of our apps work fine except for one.

In one app we will prepare and stream a PDF file to the user with the follow example code:

Response.Clear();
Response.ContentType = "binary/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + downloadName + "; size=" + downloadBytes.Length);
Response.OutputStream.Write(downloadBytes, 0, downloadBytes.Length);
Response.End();

The app will seem to hang and never stream the PDF. The app works fine with no proxy. And also if I take a pdf of the same size and store it on the server's file systems and then download from that directory it works fine. It seems to only have a problem when we try to stream using Response.

I suspected the connection wasn't being kept alive while the PDF generated (it takes about 5 to 7 seconds) but I have adjust the timeout and had no luck.

Here is my apache proxy config.

<VirtualHost *:443>

<Proxy *>

Order deny,allow
Allow from all

SSLEngine on
SSLCertificateFile C:/certs/example.crt
SSLCertificateKeyFile c:/certs/example.key
ServerName www.example.com

ProxyVia On
ProxyPass / http://127.0.0.1:5000/ timeout=360
ProxyPassReverse / http://127.0.0.1:5000/
ProxyPreserveHost On
LogLevel debug

Best Answer

So I solved my problem.

There was an internal process in the application that would use self referencing URLs to generate the PDF.

I had proxypreservehost on which was causing the PDF process to timeout because of some bad URLs it was generating.

I disabled proxypreservehost and it works like a charm!

Related Topic