Correct way to serve static files?

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:
http://forum.nginx.org/read.php?2,14978,14978#msg-14978

On Mon, Oct 19, 2009 at 8:11 PM, George [email protected] 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)$ {

thanks Daniel much appreciated :slight_smile:

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:
http://forum.nginx.org/read.php?2,14978,15096#msg-15096

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

thanks Daniel much appreciated :slight_smile:

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs