11

I have an IIS 6.0 web server exposed to the internet which isn't performing Gzipping reliably. I know it's old, but it's all i have to work with for this one instance.

What i want to do is put Nginx (or similar) infront of IIS as a reverse proxy and caching server to speed the website up. However i'm not sure if it's possible to have the nginx server gzip from itself to the web browser. If IIS passes Gzipped requests back to nginx, they get back to the browser just fine.

gzip                on;
gzip_min_length     1000;
gzip_buffers        4 8k;
gzip_http_version   1.0;
gzip_disable        "msie6";
gzip_types          text/plain text/css;
gzip_vary           on;

location / {
    proxy_set_header x-real-IP $remote_addr;
    proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
    proxy_set_header host $host;
    proxy_pass http://192.168.5.37;
}

HTTP Request (/css/components.css)

GET /css/components.css HTTP/1.1
Host: www.mydomain.co.uk
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: text/css,*/*;q=0.1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6

HTTP Response (/css/components.css)

HTTP/1.1 200 OK
Server: nginx/1.8.0
Date: Thu, 22 Oct 2015 14:26:08 GMT
Content-Type: text/css
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Last-Modified: Sat, 22 Aug 2015 09:36:54 GMT
ETag: W/"07f8614bedcd01:8beb"
X-Powered-By: ASP.NET

Is there a magic parameter i'm missing somewhere to tell it to compress the files in nginx?

Thanks!

Dean

2 Answers 2

12

You can add the gzip_proxied any; directive to your conf.

edit:

My test :
I set up a simple HTTP Server (not able to gzip by itself) on my machine (192.168.122.1) with python -m http.server 8080. When I request it I get :

[pat@morbier ~]$ curl -I -H 'Accept-Encoding: gzip,deflate' http://192.168.122.1:8080/
HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/3.5.0
Date: Thu, 22 Oct 2015 17:41:39 GMT
Content-type: text/html; charset=utf-8
Content-Length: 1197

I set up a proxy with nginx (192.168.122.224)

gzip_min_length     1000;
gzip_buffers        4 8k;
gzip_http_version   1.0;
gzip_disable        "msie6";
gzip_types          text/plain text/css;
gzip_vary           on;

location / {
    proxy_set_header x-real-IP $remote_addr;
    proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
    proxy_set_header host $host;
    proxy_pass http://192.168.122.1:8080;
}

When I request the same thing with the proxy I get

[pat@morbier ~]$ curl -I -H 'Accept-Encoding: gzip,deflate http://192.168.122.224/
HTTP/1.1 200 OK
Server: nginx/1.8.0
Date: Thu, 22 Oct 2015 17:46:08 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 1197
Connection: keep-alive

Then I add to the proxy conf

gzip on;
gzip_proxied any;

And I get

[pat@morbier ~]$ curl -I -H 'Accept-Encoding: gzip,deflate' http://192.168.122.224/
HTTP/1.1 200 OK
Server: nginx/1.8.0
Date: Thu, 22 Oct 2015 17:47:54 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Content-Encoding: gzip

You can also see it if you curl without -I (so getting the whole page), in my case it turns to be some binary displayed on the terminal, reinforcing the fact that it's compressed. When I curl the regular website that is not gzipping I get the content of the webpage (HTML).

edit2:
It actually works only with your options enabled, it seems it's no need to have gzip_proxied.
Ah you're requesting without passing the 'Accept-Encoding: gzip,deflate' header (I guess you're using telnet). It won't work in that case because you don't say to the server that you can process gzip encoded binary.
Try with curl please.

3
  • I'm afraid that made no difference. Oct 22, 2015 at 16:47
  • I have edited my answer to give you more details. Oct 22, 2015 at 17:53
  • Thanks for that, i'm going to do a fresh setup and config tomorrow. It's not making much sense at the moment. In regards to Edit2: I am passing Accept-Encoding, i've literally copied that request from Chrome's dev tools. Oct 22, 2015 at 18:44
0

Yes, this for sure can be done. I found out inadvertently (in my case, iis 8.5, which was gzipping perfectly well until I put nginx reverse proxy in front of it, and gzip from browser perspective was lost).

The config shown here:

nginx: gzip on server is lost during proxy

Will give your clients gzip interaction with nginx, regardless of what iis does.

Adjust mime types to taste.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .