Inside my server {} block, I have included a php.conf file, which works fine for all locations {} and subdirectories inside this block. But when a location block uses a alias directive, instead of the default root directive, the php files will be downloaded, instead of executed.
so my server block, looks like this:
server {
root /var/www/html;
# some other unrelated stuff
location / {
try_files $uri $uri/ =404;
rewrite ^(/)$ https://$host:$server_port/somesubdir/ permanent;
limit_except GET HEAD POST { deny all; }
return 444;
}
location /notworking {
limit_except GET HEAD POST { deny all; }
alias /var/www/somedir/subdir;
# include snippets/php.conf;
location /test {
location /test/test {
# some location stuff
}
}
include snippets/php.conf;
}
When i now use the browser an go to http(s)://mydomain.com/test/test/test.php, all is fine. PHP will be executed. But when i go to http(s)://mydomain.com/notworking/test.php, a download is started with the contents of test.php, instead of execute the php file. If i remove the comment sign from # include snippets/php.conf;
and i go to http(s)://mydomain.com/notworking/test.php, PHP is executed instead of downloaded.
snippets/php.conf looks like:
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
Is there some way, to have a global php configuration, where i don’t need to include it again, only because the only difference is the alias directive?