I have the following structure
/var/www/lsl/generalmedia
subcontent1/
picture.jpg
subcontent2/
subsub1/
picture.jpg
subsub2/
index.php
Accessible via website.com/lsl/generalmedia
I would like to make the subdirectories use the same index.php file, but serve files normally. Examples:
website.com/lsl/generalmedia/subcontent1
needs to call lsl/generalmedia/index.php
website.com/lsl/generalmedia/subcontent1/picture.jpg
must open the picture in your browser.
I have tried the following, but I'm getting 403 forbidden whenever I go to a subdirectory:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/;
index index.php;
server_name _;
location /lsl/generalmedia/ {
try_files $uri $uri/ @nested;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME /var/www/lsl/generalmedia/index.php;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
}
location @nested{
rewrite /lsl/generalmedia/(.*)$ /lsl/generalmedia/index.php?/$1 last;
}
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
}
try_files $uri @nested;
- and you can remove the nestedlocation ~ \.php$
block as it's never invoked.try_files $uri /lsl/generalmedia/index.php?$args;
so I wouldn't need the @nested location. I'm assuming it's because $uri/ tries to fetch the location, and since it doesn't have an index file it throws a 403 error? Feel free to post it as an answer, because it did what I was after.