0

UPDATE -- This is driving me nuts (or back to Apache...)

The issue is definitely symlinks and permissions

When I setup symlinks to directories in the same tree, for example /var/www/html/html2 --> /var/www/html2 it works fine. Also /var/www/html/test_alias --> /var/www/html/test works fine. It's just when pointing out a different volume that I get 403. I have sprinkled all those directories with read and exec rights and nginx ownerships, but nothing works. I have also tried adding

sendfile off; autoindex on; disable_symlinks off;

but to no avail! There must be something fundamental I am missing??


OK so I'm a beginner with Nginx, however I have successfully setup a number of Apache websites, so this can't be that difficult right?

Well, not really. At least not for me. I have struggled for a couple of days while setting up a server that can interpret PHP code. Nothing fancy at all.

I have FINALLY a version of nginx.conf that somewhat works. It loads php and html in that order, and defaults to index.php and index.html.

My root is /var/www/html, owned by user nginx. Files in "html" loads OK, but when I symlinked a directory under "html", they won't load. Can anyone give me a hint about whats wrong?

This is my conf:

events {
  worker_connections  1024;
}

http {
  index index.php index.html;
  server {
    listen 80 default_server;
    server_name _; # This is just an invalid value which will never trigger on a real hostname.
    server_name_in_redirect off;
    root  /var/www/html;

    location ~ \.php$ {
      root           /var/www/html;
      try_files $uri $uri/ =404;
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_index  index.php;
      fastcgi_split_path_info ^(.+\.php)(.*)$;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      include        fastcgi_params;
    }
  }
}

Directory structure is:

/var/www/html

these files load OK

/var/www/html/mysite

these files are not found/loaded

It would be great if someone could give me a solution to this problem. And if you also know a good reference with simple config examples I'd love to hear about them. God knows there exist plenty with incorrect/outdated/plain confusing config examples.

  • Check your error log. – Michael Hampton May 26 '16 at 21:18
  • Could be a permissions problem, they're pretty common. Copy the files from the symlink to the actual folder, as a test, setting permissions properly. – Tim May 26 '16 at 21:19
  • yes I forgot to mention that part. The error logs says 13: Permission denied. But the symlink and everything it points to is owned by nginx:nginx. But your comment triggered my tired brain, so I created a test subdir, with one php file in it, and that loaded OK. That means that the problems comes from the fact that I'm using a symlink?? – Peter Andersson May 26 '16 at 21:21
  • What does the nginx documentation say on symlinks? Permissions can be tricky to work out sometimes. – Tim May 27 '16 at 02:29
  • You don't mention your OS, but I had similar issues with CentOS and SElinux. So your error log aside, also check your SElinux audit log. – JayMcTee May 27 '16 at 12:55
  • Actually CentOS 7 is the OS running in a VM. Sysadmins choice I'm afraid. I will look into the log, if I can find it. Is it /var/log/audit/audit.log ? – Peter Andersson May 27 '16 at 15:10

1 Answers1

0

Have you made sure that your php-fpm process can access the PHP files from the place where you have made the symlinks? You should be able to test this with a simple PHP script at your /var/www/html directory which tries to open a file from your other volume.

Personally I would change the root directory to point directly to the actual place where the website root is, and not use symlinks for that purpose. And then use alias directives in location blocks to change the filesystem location for the URIs which are in different places.

Tero Kilkanen
  • 34,499
  • 3
  • 38
  • 58