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.

I have a assets manager for process css and js via php. i'm using nginx and php5-fpm for load my application. but returned css and js files not gziped.

for example my url is http://mysite.com/phpcssprocessor/mycssfile.css this file generate via php.

this is my virtual host config:

# /
    location / {
        # gzip
        gzip on;
        gzip_static on;
        gzip_proxied any;
        gzip_types application/javascript application/json application/x-javascript application/xml text/css text/javascript text/plain text/x-component text/xml;

        # disable etag
        if_modified_since off;
        add_header 'Last-Modified' '';

        # mvc rewrite
        try_files $uri $uri/ /index.php?$uri&$args;
    }
share|improve this question
add comment

2 Answers 2

up vote 0 down vote accepted

I just hit the same issue and finally solved it.

The issue was that the style.css.php file had at the top:

header("Content-type: text/css; charset: UTF-8");

And this prevented nginx from gzip-ing the file. Apparently, "gzip_type text/css" will not pick this up because of the "charset" part.

I have removed "; charset: UTF-8" from the header() argument and nginx started gziping the output.

header("Content-type: text/css");

Later I added

charset  UTF-8;

in nginx location block for that CSS processor, so I am getting the correct headers out and gzip is working.

Hope this helps somebody else as well.

share|improve this answer
add comment
  1. Is your php script setting the Content-Type: HTTP response header correctly? Does it correspond to your gzip_types options?

  2. Is your client setting the Accept-Encoding: gzip HTTP request header correctly?

  3. Does your relevant http, server or the location from which php is processed, include the directives for gzip compression? When an internal redirect takes place through try_files from a / location to a php location, specifying any kind of gzip compression in the / location would be a noop — you either have to specify it globally, or in the last location which completes the request (intermediate locations don't affect final processing).

Without all three of the above, you won't be getting any gzip compression going.

In your specific case, it seems like the try_files redirect to another location is causing you the grief, since I see you must be specifying gzip stuff in the / location only, which is likely a noop. Move the gzip directives outside of the / location. You similarly may want to move your other options away from a try_files / location as well.

share|improve this answer
    
no same script works on apache php5 module. content type is text/css. –  sweb Jan 4 '13 at 18:39
    
also yeas iv check headers via firebug, opera dragonfly and google chromium –  sweb Jan 4 '13 at 18:46
    
seems like you don't specify gzip compression in the location which you want compressed. i've just updated the answer after actually looking at your sample config snippet -- move your gzip stuff one level up from your / location, or move it into a php location, and I think it should definitely start working after that. C. –  cnst Jan 11 '13 at 19:00
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.