I want to serve multiple Laravel projects folder-wise from the same server, such as ramanath.com/projectA, ramanath.com/projectB, and so on.
The setup below is working only for root routes; however, the routes inside the apps are not working correctly.
Additionally, I want the app names to be dynamic, allowing any project name followed by the server name.
Here's the Nginx config:
server {
listen 80;
server_name ramanath.com;
root /var/www/projects;
index index.php index.html index.htm;
charset utf-8;
location /projectA {
alias /var/www/projects/projectA/public;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
location /projectB {
alias /var/www/projects/projectB/public;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
location /projectC {
alias /var/www/projects/projectC/public;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
location ~ /\.(?!well-known).* {
deny all;
}
error_page 404 /index.php;
}
With this configuration, only root routes are working for each app. How can I adjust the Nginx configuration to ensure that both root and nested routes within each project work correctly? Also, how can I make the app names dynamic, allowing any valid project name followed by the server name?