nginx 404 instead of 403 for empty directory
Solution 1:
This happens because, in most web servers, the default action for folders is "Directory listing" which is disabled by default. The same would happen in Apache usually if you disable Directory indexing. What you can do in nginx is to put =404 at the end of your try_files directive.
You can do this by putting /index.php at the end of the try_files directive. However, due to security reasons, this is not always recommendable.
Also, there is a small misunderstanding of nginx in your configuration: you should replace $uri/ with $uri/index.php or $uri/index.html or whatever. It stops at try_files $uri/ because it does find that location but the user is forbidden to access it.
Solution 2:
If you want to make nginx send a 404 whenever it would otherwise have sent a 403, that's done with error_page
:
server {
root /var/www/example.com/web;
error_page 404 /s/404.html;
error_page 403 =404 /s/404.html;
location /s/404.html { internal; }
# etc
}
The location
line makes http://example.com/s/404.html
produce a 404 as well.