# Is 'try\_files' or 'rewrite' aware of 'gzip\_static'?

**URL:** <https://www.ruby-forum.com/t/is-try-files-or-rewrite-aware-of-gzip-static/220352>\
**Category:** NGINX\
**Created:** [June 6, 2012, 5:01pm UTC](https://www.ruby-forum.com/t/is-try-files-or-rewrite-aware-of-gzip-static/220352 "2012-06-06T17:01:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [June 6, 2012, 5:01pm UTC](https://www.ruby-forum.com/t/is-try-files-or-rewrite-aware-of-gzip-static/220352/1 "2012-06-06T17:01:01Z")

</div>

Hi,

I’m running a quite huge TYPO3 installation on nginx (several other  
installations to follow on that host). In this case I’m using (or want  
to use) nc\_staticfilecache as an extension to speed things up a  
little. 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.

My try\_files directive looks like this:  
try\_files  
/typo3temp/tx\_ncstaticfilecache/cache/$host${request\_uri}index.html  
@fetch\_from\_typo3;

The index.html.gz within the same directory does exist and  
‘gzip\_static’ is set to ‘on’.

Best,  
Chris

---

<div class="post-metadata">

**Author:** ![SSChristian\_BSSnnin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@SSChristian\_BSSnnin](https://www.ruby-forum.com/u/SSChristian_BSSnnin)\
**Post date:** [June 6, 2012, 10:45pm UTC](https://www.ruby-forum.com/t/is-try-files-or-rewrite-aware-of-gzip-static/220352/2 "2012-06-06T22:45:24Z")

</div>

On Wed, Jun 06, 2012 at 05:00:35PM +0200, Christian B. 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;

[Module ngx\_http\_core\_module](http://nginx.org/r/try_files) 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  
time.

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.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
