I have the following config for my nginx server:
server {
listen 80 default_server;
server_name example.com www.example.com;
root /var/www/example.com/web;
index index.php index.html;
location / {
# try to serve file directly, fallback to rewrite
try_files $uri $uri/ @rewriteapp;
}
location @rewriteapp {
# rewrite all to index.php
rewrite ^(.*)$ /index.php last;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
}
}
And the following directory structure:
/var/www/example.com/:
- /index.php
- /dir/index.html
- /empty/
When client hits: 'example.com/dir/' then index.html is served.
When client hits some non-existent URL like this: 'example.com/non-existent/' then index.php is served in the root directory.
But when client hits: 'example.com/empty/' then 403 status code is sent.
- Why it's sending 403 when 404 is more appropriate cause index file is missing in this directory?
- How do I map such requests to index.php (@rewriteapp)?