is 'try_files' or 'rewrite' aware of 'gzip_static'?

Francis Daly francis at
Wed Jun 6 20:44:54 UTC 2012

On Wed, Jun 06, 2012 at 05:00:35PM +0200, Christian Bönning wrote:

Hi there,

> This extension writes the html document which is sent to the
> client down to disk as a single uncompressed file and - depending on
> its configuration - another one which is gzipped for static delivery
> for subsequent requests to the same document.
> Now the question is if my rewrite or try_files directives will try to
> deliver the gzipped version of the page.

You've shown a "try_files" directive, but no rewrite directive.

Quick testing indicates that for try_files, the answer is "yes and no",
with a fuller explanation below.

> My try_files directive looks like this:
> try_files /typo3temp/tx_ncstaticfilecache/cache/$host${request_uri}index.html
> @fetch_from_typo3; indicates that it means "take these urls
in turn, convert them into filenames by prefixing the relevant 'alias'
or 'root' value, and for the first such file that exists, process the
corresponding url normally".

So with the above line, unless you have a "typo3temp" directory inside
/usr/local/nginx/html, it is going to fall back to the @location every

Once that is fixed, then if the index.html file does not exist, try_files
will fall back to the @location (so "it does not heed gzip_static"). But
if index.html does exist, then processing continues of that url -- which
will serve index.html.gz if appropriate (so "it does heed gzip_static").

Overall: try_files is not aware of gzip_static; but nginx will still
honour it if both the non-gz and .gz files exist. This differs from
the "normal" gzip_static handling which will serve the .gz version if
appropriate, whether or not non-gz exists.

> The index.html.gz within the same directory does exist and
> 'gzip_static' is set to 'on'.

So long as both index.html and index.html.gz are there, try_files should
Just Work.

I tested this on a 1.2.0 build, in case that matters.

rewrite can be tested separately, if you have a sample directive.

Francis Daly        francis at

More information about the nginx mailing list