I almost have it working, but even then not sure if it’s properly implemented. (I’m new to Nginx!)
My test has this directory structure:
/index.php (root directory front controller)
/test/index.php (sub directory front controller)
/include/include.php (some PHP include)
Files named index.php are the front controllers.
The Nginx server block:
server {
listen 80;
server_name mysite.com;
root /var/www/mysite.com/http;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri @rewrite;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location @rewrite {
rewrite ^ /index.php last;
}
}
These cases currently work and need to work like this:
1. http://mysite.com/ => /index.php (exists)
2. http://mysite.com/test => /test/index.php (exists)
3. http://mysite.com/test/index.php => /test/index.php (exists)
4. http://mysite.com/test/foobar => /index.php (/test/foobar didn't exist)
5. http://mysite.com/asdf => /index.php (/asdf didn't exist)
6. http://mysite.com/asdf.php => /index.php (/asdf.php didn't exist)
7. http://mysite.com/asdf/index.php => /index.php (didn't exist; the try_files @rewrite fixes this, otherwise I get "No input file specified.")
The case I don’t have yet is:
8. http://mysite.com/include/include.php => /index.php
Currently accessing a PHP file that exists that isn’t a front controller is processing that script. I can understand why it’s doing it, it’s try(ing)_files $uri @rewrite and finding include.php. I’ve been trying to fix it with rewrites, but no dice. Or is there a better way, with location blocks/try_files?
In general am I going about this server block correctly for my intentions?
How about …
This will serve …
… which is what your question suggests you want (last one seems strange to me)