51

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.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
stecog
  • 2,221
  • 10
  • 29
  • 39
  • Have a look at http://nginx.org/en/docs/http/ngx_http_core_module.html#disable_symlinks – Andy Sep 23 '14 at 09:54
  • 3
    OK i resolved with `disable_symlinks off;`. Thanks! – stecog Sep 23 '14 at 11:08
  • No problem.Have a nice day! – Andy Sep 23 '14 at 11:09
  • 1
    Please either type your solution as an answer and accept it (it's fair behaviour here) or elsewhere delete your question. – leonbloy Sep 23 '14 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. –  May 01 '15 at 00: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. – Shou Sep 02 '15 at 00:50

3 Answers3

69

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

http {
    disable_symlinks off;
}
Nakilon
  • 144
  • 1
  • 10
stecog
  • 2,221
  • 10
  • 29
  • 39
  • 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. – frozen-flame Dec 10 '15 at 09:17
  • 2
    @frozen-flame `disable_symlinks` was added in version 1.1.15 ([see docs](http://nginx.org/en/docs/http/ngx_http_core_module.html#disable_symlinks)), 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)? – Ville May 07 '16 at 01:47
  • 4
    Context to use `disable_symlinks`: `http, server, location` – Thiago Pereira Apr 04 '19 at 16:56
4

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)

Anthon
  • 78,313
  • 42
  • 165
  • 222
2

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;
muru
  • 69,900
  • 13
  • 192
  • 292