58

Nginx does not follow symbolic links. I get a 404 error. In my directory, I have this link:

lrwxrwxrwx  1 root root    48 Sep 23 08:52 modules -> /path/to/dir/

but the files stored in /path/to/dir aren't found.

6
  • Have a look at nginx.org/en/docs/http/… Commented Sep 23, 2014 at 9:54
  • 3
    OK i resolved with disable_symlinks off;. Thanks! Commented Sep 23, 2014 at 11:08
  • 1
    Please either type your solution as an answer and accept it (it's fair behaviour here) or elsewhere delete your question. Commented Sep 23, 2014 at 11:19
  • 1
    Any other ideas? I'm having this problem, I tried putting disable_symlinks off; in my conf (even though that is actually the default anyways) and nothing is working. Commented May 1, 2015 at 0:43
  • 2
    @Jason make sure the path to the symlinked file is readable and executable, e.g. run chmod +rx on all the preceding folders, and the file itself. Commented Sep 2, 2015 at 0:50

3 Answers 3

76

I insert disable_symlinks off; in my nginx.conf and i resolved, works fine!

http {
    disable_symlinks off;
}
3
  • I got nginx: [emerg] unknown directive "disable_symlinks" in /usr/local/etc/nginx/nginx.conf:22 after doing this. I was using nginx/1.8.0 on Mac OS X. Commented Dec 10, 2015 at 9:17
  • 2
    @frozen-flame disable_symlinks was added in version 1.1.15 (see docs), so it should have worked. Are you sure you were on 1.8.0, and that it was in the allowed context (http, server, or location)? Commented May 7, 2016 at 1:47
  • 7
    Context to use disable_symlinks: http, server, location Commented Apr 4, 2019 at 16:56
7

Use 'bind' option by mounting folders =)

sudo nano /etc/fstab

Type:

/path/where/my/big/files_dir /var/www/myhost/media_dir bind defaults,bind 0 0

(no symlinks & don't forget restart vds/cpu)

5

I found the solution on this post.

More specifically, these lines:

fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.