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;
}
Is your php script setting the
Content-Type:
HTTP response header correctly? Does it correspond to yourgzip_types
options?Is your client setting the
Accept-Encoding: gzip
HTTP request header correctly?Does your relevant
http
,server
or thelocation
from whichphp
is processed, include the directives for gzip compression? When an internal redirect takes place throughtry_files
from a/
location
to aphp
location
, specifying any kind of gzip compression in the/
location
would be a noop — you either have to specify it globally, or in the lastlocation
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 anotherlocation
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 atry_files
/
location
as well.I just hit the same issue and finally solved it.
The issue was that the style.css.php file had at the top:
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.
Later I added
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.