# Try\_files and expires

**URL:** <https://www.ruby-forum.com/t/try-files-and-expires/243597>\
**Category:** NGINX\
**Created:** [December 8, 2015, 3:35pm UTC](https://www.ruby-forum.com/t/try-files-and-expires/243597 "2015-12-08T15:35:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [December 8, 2015, 3:35pm UTC](https://www.ruby-forum.com/t/try-files-and-expires/243597/1 "2015-12-08T15:35:17Z")

</div>

Hi,

I have a case with a CMS (pimcore) and setting the expires directive.

```
 location / {
     # First attempt to serve request as file, then as directory,

```

then fall back to index.php  
try\_files $uri $uri/ /website/var/assets/$uri /index.php?$args;  
index index.php;  
}

So, there are “assets” (pdfs, mostly but also some images) in a  
subdirectory.

This works, but this directive:

```
 location ~*

```

.(jpe?g|gif|png|bmp|ico|css|js|pdf|zip|htm|html|docx?|xlsx?|pptx?|txt|wav|swf|avi|mp\d)$  
{  
access\_log off;  
log\_not\_found off;

```
     expires 1w;
 }

```

breaks the first directive.

Is there a way to have both?

Rainer

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 9, 2015, 5:31pm UTC](https://www.ruby-forum.com/t/try-files-and-expires/243597/2 "2015-12-09T17:31:30Z")

</div>

On Tue, Dec 08, 2015 at 03:34:28PM +0100, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

Hi there,

> This works, but this directive:
> 
> Is there a way to have both?

One request is handled in one location. Put the configuration that you  
want, in the location that is matched.

It is not immediately clear to me what response you want for a request  
for /one.pdf.

Perhaps add the try\_files to the regex location?

## f

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