This should work (I verified this with somewhat simpler config, though). Igor Sysoev recommends to use regex locations as little as possible, by the way.
location /img {
if ($arg_max) { expires max; }
...
}
location /posts-img {
if ($arg_max) { expires max; }
...
}
location ~ /(?:posts-)?img/.*-res- {
access_log off;
expires max;
rewrite "/img/(.*)-res-.{8}(.*)" /img/$1$2?max=1;
rewrite "/posts-img/(.*)-res-.{8}(.*)" /posts/$1$2?max=1;
}
Unfortunately, I can't comment on cnst's post - so I'm going to answer here.
The nginx_http_proxy
module by default talks with the upstream in HTTP/1.0.
This can be changed with the directive proxy_http_version 1.1
.
This might also be the cause for your script to return a HTTP/1.0 answer, although chunked coding and status code 307
don't exist in this version.
You shouldn't use chunked coding with a redirect either, as this doesn't really make sense.
Additionally, it seems like nginx doesn't pass chunks from the upstream to the client one by one, but it buffers the upstream's response.
The Content-Length
header field is ignored because it is against the definition.
I had to look at the source code of the module because all this appears to be undocumented.
You may want to try out the nginx_tcp_proxy_module
to proxy the chunked content as raw TCP data: Module at Github
UPDATE (10.04.14)
The
nginx_http_proxy
module has support for
X-Accel-*
headers, of which one (
X-Accel-Buffering: yes|no
) controls whether the response should be buffered or not.
Adding this header (X-Accel-Buffering: no
) to the backend's response will cause nginx to directly pass chunks to the client.
This header allows to control buffering on an per-request basis.
The module also has a configuration directive proxy_buffering
to enable or disable response buffering (not buffering means sending chunks will work).
Proxy buffering (both header and directive based) is documented here.
Best Answer
Just turning it on with gzip_static on didn't work for me. I had to use the gzip_proxied before it started working.
Note the last line adds another two headers that help debugging. You can see these using a great plugin for Firefox called "Live HTTP Headers", which I found super useful for debugging a load of things around headers and caching. Note that "curl -I" doesn't work as it doesn't send a header saying it accepts gzip encoding.
You should also make sure the files have the same modification date
Here are the headers I get back when I use the location config above