在Nginx中closuresgzip

gzip如何closures一个特定的位置和所有的子目录? 我的主要网站是在http://mydomain.com ,我想closureshttp://mydomain.com/foohttp://mydomain.com/foo/barclosuresgzip。 在nginx.conf打开gzip

我尝试closuresgzip ,如下所示,但Chrome开发工具中的响应头显示Content-Encoding:gzip

gzip / output缓冲应该如何正确禁用?

尝试

 server { listen 80; server_name www.mydomain.com mydomain.com; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; root /var/www/mydomain/public; index index.php index.html; location / { gzip on; try_files $uri $uri/ /index.php?$args ; } location ~ \.php$ { fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_read_timeout 300; } location /foo/ { gzip off; try_files $uri $uri/ /index.php?$args ; } } 

UPDATE

我closures了nginx.conf gzip ,并尝试使用命名的位置。 不过gzip现在总是closures,并且gzip on;location /块似乎不会变成gzip回来。 有任何想法吗?

 server { listen 80; server_name www.mydomain.com mydomain.com; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; root /var/www/mydomain/public; index index.php index.html; location / { try_files $uri $uri/ @php; } location /foo/ { try_files $uri $uri/ @php_nogzip; } location @php { gzip on; try_files $uri $uri/ /index.php?$args ; } location @php_nogzip { gzip off; try_files $uri $uri/ /index.php?$args ; } location ~ \.php$ { fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_read_timeout 300; } } 

我假设你请求的URL是在location ^~ /foo/内由try_files处理的,由于没有这些文件,它们在内部被redirect到另一个没有inheritancegzip off location处理器。

尝试在/foo位置使用“命名的位置”,然后定义“命名”的位置@fooNoGzipgzip off里面和fascgi_pass东西。

由于每个位置都是独立的,因此在@php_nogzip上设置gzip off将不适用于location ~ \.php$ ,它仍然使用nginx / server默认值。 这就是为什么你看到gzip,因为这是默认的。 只有@php_nogzip的try_files传送的文件才会被压缩。

我看到的唯一方法是使用地图。 在http块中使用:

 map $uri $gz { default "on"; ~/foo/ "off"; } 

然后在服务器上:

  location ~ \.php$ { gzip $gz; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_read_timeout 300; }