Forum: NGINX following symlinks

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2974d09ac2541e892966b762aad84943?d=identicon&s=25 jackdempsey (Guest)
on 2009-03-31 21:49
(Received via mailing list)
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: http://forum.nginx.org/read.php?2,677,677#msg-677
F5a6ed477b109fe6acc11a5a8f87e7e8?d=identicon&s=25 Michael Shadle (Guest)
on 2009-03-31 22:14
(Received via mailing list)
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.
F5a6ed477b109fe6acc11a5a8f87e7e8?d=identicon&s=25 Michael Shadle (Guest)
on 2009-03-31 22:14
(Received via mailing list)
On Tue, Mar 31, 2009 at 1:08 PM, Michael Shadle <mike503@gmail.com>
wrote:

> also include which version you're running so Igor knows.

disregard the last line. you did include it :p
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-04-01 07:42
(Received via mailing list)
On Tue, Mar 31, 2009 at 01:08:19PM -0700, Michael Shadle 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.
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-04-01 09:18
(Received via mailing list)
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  ...
   }
2974d09ac2541e892966b762aad84943?d=identicon&s=25 jackdempsey (Guest)
on 2009-04-01 17:11
(Received via mailing list)
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: http://forum.nginx.org/read.php?2,677,714#msg-714
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-04-01 17:20
(Received via mailing list)
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;
     }
F5a6ed477b109fe6acc11a5a8f87e7e8?d=identicon&s=25 Michael Shadle (Guest)
on 2009-04-01 19:10
(Received via mailing list)
2009/4/1 Igor Sysoev <is@rambler-co.ru>:
> 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 :)
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-04-01 19:14
(Received via mailing list)
On Wed, Apr 01, 2009 at 10:04:13AM -0700, Michael Shadle 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 :)

I'm going to release tomorrow 0.6.36 with try_files.
F5a6ed477b109fe6acc11a5a8f87e7e8?d=identicon&s=25 Michael Shadle (Guest)
on 2009-04-01 19:23
(Received via mailing list)
2009/4/1 Igor Sysoev <is@rambler-co.ru>:

> 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 :)
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-04-01 22:11
(Received via mailing list)
On Wed, Apr 01, 2009 at 10:13:55AM -0700, Michael Shadle 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 :)

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.
2974d09ac2541e892966b762aad84943?d=identicon&s=25 jackdempsey (Guest)
on 2009-04-03 17:13
(Received via mailing list)
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: http://forum.nginx.org/read.php?2,677,783#msg-783
2974d09ac2541e892966b762aad84943?d=identicon&s=25 jackdempsey (Guest)
on 2009-04-04 09:46
(Received via mailing list)
Igor Sysoev Wrote:
-------------------------------------------------------
> $uri.html  @rails;
> > those checks.
> http://sysoev.ru/en/
>
>

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

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,677,782#msg-782
This topic is locked and can not be replied to.