Nginx反向代理Gzip到客户端

我有一个IIS 6.0 Web服务器暴露在互联网上,不能可靠地执行Gzipping。 我知道这已经很久了,但是这一切都需要我的努力。

我想要做的是把IIS的Nginx(或类似的)infront作为一个反向代理和caching服务器,以加快网站。 然而,我不知道是否有可能从本身的nginx服务器gzip到web浏览器。 如果IIS将Gzip请求传递回nginx,他们会回到浏览器就好了。

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请求(/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响应(/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 

有没有一个神奇的参数我错过某处告诉它压缩nginx中的文件?

谢谢!

院长

你可以添加gzip_proxied any; 指令你的conf。

编辑:

我的testing:
我使用python -m http.server 8080在我的机器(192.168.122.1)上设置了一个简单的HTTP服务器(不能自行gzip)。 当我请求时,我得到:

 [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 

我用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; } 

当我请求与代理服务器相同的东西时,

 [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 

然后我添加到代理conf

 gzip on; gzip_proxied any; 

我得到了

 [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 

你也可以看到它,如果你没有-I(所以得到整个页面)curl,在我的情况下,它会变成一些二进制显示在terminal上,加强事实,它是压缩的。 当我蜷缩不正常的网站时,我得到了网页的内容(HTML)。

EDIT2:
它实际上只适用于你的选项启用,似乎没有必要有gzip_proxied。
啊,你要求没有通过'接受编码:gzip,deflate'标题(我猜你正在使用telnet)。 它不会在这种情况下工作,因为你不要说服务器,你可以处理gzip编码二进制。
请尝试与curl。

是的,这当然可以做到。 我无意中发现了(在我的例子中,iis 8.5,这是非常好的,直到我把nginx反向代理放在它的前面,从浏览器的angular度来看gzip丢失了)。

这里显示的configuration:

nginx:服务器上的gzip在代理期间丢失

将给你的客户与nginx的gzip交互,不pipeiis是什么。

调整MIMEtypes的味道。