# Setting expires header results in 404?

**URL:** <https://www.ruby-forum.com/t/setting-expires-header-results-in-404/186254>\
**Category:** NGINX\
**Created:** [April 3, 2010, 12:45am UTC](https://www.ruby-forum.com/t/setting-expires-header-results-in-404/186254 "2010-04-03T00:45:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RoastedPeanut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f1d935/32.png) [@RoastedPeanut](https://www.ruby-forum.com/u/RoastedPeanut)\
**Post date:** [April 3, 2010, 12:45am UTC](https://www.ruby-forum.com/t/setting-expires-header-results-in-404/186254/1 "2010-04-03T00:45:55Z")

</div>

location ~\* .(ico|css|js|gif|jpg|png)$ {  
expires 7d;  
}  
If I add this to my server conf it will cause all those requests to fail  
with a 404…I’m feeling silly for missing this, and I know it’s probably  
very easy to fix…but how? 🙂

Posted at Nginx Forum:

> **[Setting expires header results in 404 ?](https://forum.nginx.org/read.php?2,70739,70739#msg-70739)**
>
> location ~\* \\.(ico|css|js|gif|jpg|png)$ { expires 7d; } If I add this to my server conf it will cause all those requests to fail with a 404..I'm feeling silly for missing this, and I know it's probably very easy to fix...but how? :)

---

<div class="post-metadata">

**Author:** ![RoastedPeanut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f1d935/32.png) [@RoastedPeanut](https://www.ruby-forum.com/u/RoastedPeanut)\
**Post date:** [April 3, 2010, 12:59am UTC](https://www.ruby-forum.com/t/setting-expires-header-results-in-404/186254/2 "2010-04-03T00:59:23Z")

</div>

Hello!

On Fri, Apr 02, 2010 at 06:45:25PM -0400, RoastedPeanut wrote:

> location ~\* .(ico|css|js|gif|jpg|png)$ {  
> expires 7d;  
> }  
> If I add this to my server conf it will cause all those requests  
> to fail with a 404..I’m feeling silly for missing this, and I  
> know it’s probably very easy to fix…but how? 🙂

Most likely you have something like this:

```
root /path/to/nowhere;

location / {
    root /path/to/root;
}

```

Adding

```
location ~* \.(ico|css|js|gif|jpg|png)$ {
    expires 7d;
}

```

results in these files being searched in nowhere. The reason is  
simple: nginx uses configuration in “location ~\* .(…)$” which  
has no root explicitly set, and therefore root is inherited from  
server/http level (or compiled-in default).

Maxim D.

---

<div class="post-metadata">

**Author:** ![RoastedPeanut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f1d935/32.png) [@RoastedPeanut](https://www.ruby-forum.com/u/RoastedPeanut)\
**Post date:** [April 3, 2010, 9:26am UTC](https://www.ruby-forum.com/t/setting-expires-header-results-in-404/186254/3 "2010-04-03T09:26:46Z")

</div>

Thanks, worked like a charm 🙂

Posted at Nginx Forum:

> **[Re: Setting expires header results in 404 ?](https://forum.nginx.org/read.php?2,70739,70780#msg-70780)**
>
> location ~\* \\.(ico|css|js|gif|jpg|png)$ { expires 7d; } If I add this to my server conf it will cause all those requests to fail with a 404..I'm feeling silly for missing this, and I know it's probably very easy to fix...but how? :)
