# Correct way to serve static files?

**URL:** <https://www.ruby-forum.com/t/correct-way-to-serve-static-files/177524>\
**Category:** NGINX\
**Created:** [October 19, 2009, 7:21pm UTC](https://www.ruby-forum.com/t/correct-way-to-serve-static-files/177524 "2009-10-19T19:21:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![George](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71e660/32.png) [@George](https://www.ruby-forum.com/u/George)\
**Post date:** [October 19, 2009, 7:21pm UTC](https://www.ruby-forum.com/t/correct-way-to-serve-static-files/177524/1 "2009-10-19T19:21:53Z")

</div>

I’ve been looking over lots of nginx configurations and the way to serve  
static files differed slightly, so which is the correct way as i’ve seen  
the following syntax

location ~\* .(jpg|jpeg|gif|css|png|js|ico)$ {

vs

```
    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {

```

what’s the difference between the 2 ?

thanks

George

Posted at Nginx Forum:

> **[Correct way to serve static files ?](https://forum.nginx.org/read.php?2,14978,14978#msg-14978)**
>
> I've been looking over lots of nginx configurations and the way to serve static files differed slightly, so which is the correct way as i've seen the following syntax location ~\* \\.(jpg|jpeg|gif|css|png|js|ico)$ { vs location ~\* ^.+.(jpg|jpeg|gif

---

<div class="post-metadata">

**Author:** ![George](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71e660/32.png) [@George](https://www.ruby-forum.com/u/George)\
**Post date:** [October 19, 2009, 10:06pm UTC](https://www.ruby-forum.com/t/correct-way-to-serve-static-files/177524/2 "2009-10-19T22:06:23Z")

</div>

On Mon, Oct 19, 2009 at 8:11 PM, George [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> what’s the difference between the 2 ?

Read up on regexs, these are both similar in that they match urls ending  
in  
(jpg, jpeg etc.)  
However there is one tiny difference, the first one requires there be a  
dot  
before the extension, whereas the second doesn’t, eg. it should match  
“/somethingjpg” whereas the first would only match “/something.jpg”

The second one looks wrong, it probably wanted to be location ~\*  
^.+.(jpg|jpeg|gif|css|png|js|ico)$ {

---

<div class="post-metadata">

**Author:** ![George](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71e660/32.png) [@George](https://www.ruby-forum.com/u/George)\
**Post date:** [October 20, 2009, 1:18am UTC](https://www.ruby-forum.com/t/correct-way-to-serve-static-files/177524/3 "2009-10-20T01:18:26Z")

</div>

thanks Daniel much appreciated 🙂

I had my configs with first line so guess it was a lucky copy and paste.  
But i’ve seen a handful of configs online exactly like the second line  
hmmm.

Posted at Nginx Forum:

> **[Re: Correct way to serve static files ?](https://forum.nginx.org/read.php?2,14978,15096#msg-15096)**
>
> I've been looking over lots of nginx configurations and the way to serve static files differed slightly, so which is the correct way as i've seen the following syntax location ~\* \\.(jpg|jpeg|gif|css|png|js|ico)$ { vs location ~\* ^.+.(jpg|jpeg|gif

---

<div class="post-metadata">

**Author:** ![George](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71e660/32.png) [@George](https://www.ruby-forum.com/u/George)\
**Post date:** [October 20, 2009, 3:19pm UTC](https://www.ruby-forum.com/t/correct-way-to-serve-static-files/177524/4 "2009-10-20T15:19:40Z")

</div>

On Mon, Oct 19, 2009 at 07:12:14PM -0400, George wrote:

> thanks Daniel much appreciated 🙂
> 
> I had my configs with first line so guess it was a lucky copy and paste. But i’ve seen a handful of configs online exactly like the second line hmmm.

Current PCRE library handles equally these regexes

```
    location ~* \.(jpg|jpeg|gif|css|png|js|ico)$ {

```

and

```
    location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico)$ {

```

It parses a line from its start, but not from ‘$’ anchor.
