I’m seeking assistance with setting up nginx to host a React application as the frontend alongside a Laravel backend handling specific API and admin routes. While React manages most paths, I need nginx to direct requests for /api and /admin to the Laravel application.
Currently, I’m encountering issues where accessing these routes leads to errors like “file not found” or a blank page. I’ve already attempted to reinstall nginx and re-clone both projects, and I’ve verified that php-fpm is running properly.
Below is my nginx configuration:
server {
listen 80;
server_name mydomain.com;
client_max_body_size 100M;
location / {
root /var/www/html/react/dist;
try_files $uri $uri/ /index.html;
}
location ~ ^/(api|admin) {
root /var/www/html/app/public;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_read_timeout 300;
}
location ~ /\.(ht|env) {
deny all;
}
}
What might I be overlooking in this setup? Any advice would be greatly appreciated.