Following symlinks

Hi all,

I’m trying to serve up some static files that I’ve linked to via a
symlink. The -f check is failing:

check if the file exists and serve it

if (-f $request_filename) {
  access_log        off;
 expires           1d;
 break;

}

as its obviously not a file. I saw something that suggested using -e
instead for symlinks, but that doesn’t seem to work for me either (this
is version 0.6.32 fwiw). Anyone have any suggestions on what I can do to
have symlink’ed files served up?

thanks so much,
jack

Posted at Nginx Forum: following symlinks

have you tried -d ?

a bit redundant as -e i think is the same as -f and -d … but worth a
shot

also include which version you’re running so Igor knows.

On Tue, Mar 31, 2009 at 1:08 PM, Michael S. [email protected]
wrote:

also include which version you’re running so Igor knows.

disregard the last line. you did include it :stuck_out_tongue:

On Tue, Mar 31, 2009 at 01:08:19PM -0700, Michael S. wrote:

have you tried -d ?

a bit redundant as -e i think is the same as -f and -d … but worth a shot

-e tests file/directory/symlink existance.

Thanks Igor, Mike. I’ve tried the -e flag, and it doesn’t seem to follow
the symlinks correctly:

check if the file exists and serve it

if (-e $request_filename) {
  access_log        off;
  expires           1d;
  break;

}

# check for an index file, and serve that
if (-e $request_filename/index.html) {
  rewrite (.*) $1/index.html break;
}

# rails page caching
if (-e $request_filename.html) {
  rewrite (.*) $1.html break;
}

# route traffic to sae-conf cluster
if (!-e $request_filename) {
  proxy_pass http://site-here;
  break;
}

When I make the link a hardlink, it does work correctly (with just the
-f flag). The -e test should work on 0.6.32, right? Is there anything
else I might need to do, any option, compile flag, etc? I can’t imagine
so, but I’m pretty confident given my local tests that its not working.
Anyone have a config with -e working on symbolic links? Maybe its worth
putting together a demo site/config myself and seeing if it would work
for others. Thanks again for the help.

Posted at Nginx Forum: Re: following symlinks

On Tue, Mar 31, 2009 at 03:38:40PM -0400, jackdempsey wrote:

as its obviously not a file. I saw something that suggested using -e instead for symlinks, but that doesn’t seem to work for me either (this is version 0.6.32 fwiw). Anyone have any suggestions on what I can do to have symlink’ed files served up?

What you want to do if the file does not exist ? If serving by fastcgi,
then

location / {
error_page 404 = @fastcgi;
}

location @fastcgi {
fastcgi_pass …
}

2009/4/1 Igor S. [email protected]:

You should get http://sysoev.ru/nginx/patch.try_files.0.6.35.5
and use

  location / {
    try_files  $uri  $uri/index.html $uri.html  @rails;
  }

  location @rails {
    proxy_pass  http://site-here;
  }

Exactly.

try_files was going to be what I was going to say the minute I saw all
those checks.

Also - how about just upgrading? 0.7.x is just as stable for us
basically :slight_smile:

On Wed, Apr 01, 2009 at 10:57:48AM -0400, jackdempsey wrote:

if (-e $request_filename/index.html) {
  proxy_pass http://site-here;
  break;
}

When I make the link a hardlink, it does work correctly (with just the -f flag). The -e test should work on 0.6.32, right? Is there anything else I might need to do, any option, compile flag, etc? I can’t imagine so, but I’m pretty confident given my local tests that its not working. Anyone have a config with -e working on symbolic links? Maybe its worth putting together a demo site/config myself and seeing if it would work for others. Thanks again for the help.

You should get http://sysoev.ru/nginx/patch.try_files.0.6.35.5
and use

 location / {
     try_files   $uri  $uri/index.html $uri.html  @rails;
 }

 location @rails {
     proxy_pass  http://site-here;
 }

On Wed, Apr 01, 2009 at 10:04:13AM -0700, Michael S. wrote:

š š }

Exactly.

try_files was going to be what I was going to say the minute I saw all
those checks.

Also - how about just upgrading? 0.7.x is just as stable for us basically :slight_smile:

I’m going to release tomorrow 0.6.36 with try_files.

On Wed, Apr 01, 2009 at 10:13:55AM -0700, Michael S. wrote:

I’ve been running 0.7.x since I started using nginx - it has a bug
here and there, but you patch them quickly and it’s never been
anything that has actually reduced performance/functionality/etc. for
me. In fact, you add features quick that benefit me and I receive
those benefits because I am on 0.7.x and I don’t have to ask you to
backport them :slight_smile:

Before 0.6.x I developed the single branch. However, I understand that
by no means all people like development versions. My very self is in
the same position in relation to the FreeBSD CURRENT/STABLE branches.
Therefore a stable branch should exist at least for bugfixes.
I do not want to add many new features to the stable branch, however,
I do want that the try_files would become a common pattern instead of
if/rewrite’s, so I will add it to stable branch.

2009/4/1 Igor S. [email protected]:

I’m going to release tomorrow 0.6.36 with try_files.

Still, that is additional overhead for you to maintain two branches.
Sounds like you’re planning 0.8.x around June anyway… and with some
people running 0.5.x still too, I’d say let’s all try to make a push
for more people to run 0.7.x - since that will soon (hopefully) be the
stable branch once you finish the cache stuff in April/May (if I
recall you post)

I’ve been running 0.7.x since I started using nginx - it has a bug
here and there, but you patch them quickly and it’s never been
anything that has actually reduced performance/functionality/etc. for
me. In fact, you add features quick that benefit me and I receive
those benefits because I am on 0.7.x and I don’t have to ask you to
backport them :slight_smile:

Just a quick follow up…try_files is definitely nicer and more
concise, but i realized my error and want to make it obvious here to
anyone who might do the same: be very careful about using relative vs
absolute symbolic links.

file → a/bar.png

is very different (and won’t work) than

file → /var/www/path/to/a/bar.png

Thanks again Mike and Igor, really appreciate sticking with me on this.

Posted at Nginx Forum: Re: following symlinks

Igor S. Wrote:

$uri.html @rails;

those checks.
Igor Sysoev

Wonderful. It sounds like try_files is the better way to go. Will give
it a try now, thanks!

Posted at Nginx Forum: Re: following symlinks