I had this configuration working flawlessly:
# Route for Laravel Backend
location ~ ^/(app|api|sanctum|admin) {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
# Nginx Pass requests to PHP-FPM for Laravel Backend
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass backend:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
then i wanted to cover every call to the backend under a unique prefix:
location ^~ /backend/ {
# Remove the '/backend' prefix and pass the remaining path to index.php
rewrite ^/backend/(.*)$ /$1 break;
try_files $uri $uri/ /index.php?$query_string;
}
# PHP-FPM Configuration
location ~ .php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass backend:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param REQUEST_URI $request_uri;
}
The problem is that the php backend application is actually reached, but it seems that only the index.php file is delivered without it being able to get the backend routes
[2024-04-03 09:05:58] production.INFO: Global Request URI: /