Step 8: Configure Nginx
Create an Nginx server block:
nano /etc/nginx/sites-available/ai-education-studioAdd the following configuration:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/ai-education-studio/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
}Enable the site:
ln -s /etc/nginx/sites-available/ai-education-studio /etc/nginx/sites-enabled/
nginx -t
systemctl reload nginxInfo: The
try_filesdirective is critical. It ensures that Laravel handles all routing (including React Router paths) instead of Nginx returning 404s.
Last updated on