Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How can gzip be turned off for a particular location and all its sub-directories? My main site is at http://mydomain.com and I want to turn gzip off for both http://mydomain.com/foo and http://mydomain.com/foo/bar. gzip is turned on in nginx.conf.

I tried turning off gzip as shown below, but the Response Headers in Chrome's dev tools shows that Content-Encoding:gzip.

How should gzip/output buffering be disabled properly?

Attempt:

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

I turned off gzip in nginx.conf and tried using named locations. However gzip is now always off, and gzip on; in the location / block does not seem to turn gzip back on. Any ideas?

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

}
share|improve this question
1  
Is your application compressing its response? –  Michael Hampton Oct 14 '12 at 18:20
    
Sorry for a newb question, but how does my application (running on PHP framework Laravel) compress the response? –  Nyxynyx Oct 14 '12 at 20:35
add comment

1 Answer

up vote 1 down vote accepted

I'd suppose that URLs you're requesting are being handled with try_files inside location ^~ /foo/ and due to absence of those files, they're internally re-directed to another location handler not having gzip off inherited.

Try using "named location" in /foo location, and then define that "named" location @fooNoGzip with gzip off inside and fascgi_pass stuff.

share|improve this answer
    
Thanks, I tried your suggested and updated the original post with the new conf, but now gzip if always turned off. Can you take a look? :) –  Nyxynyx Oct 16 '12 at 17:11
    
@Nyxynyx, solved? –  poige Nov 2 '12 at 19:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.