Tricks

Fix Filament assets not loading in Nginx

Nov 16, 2022
Ida Bagus Gede Pramana Adi Putra
FAQ, Integration

If your Laravel and Filament are being served by Nginx, there's a chance that you might run into an issue where the Filament assets are not loaded properly.

To overcome this issue, you need to tell Nginx that the /filament should be handled by Laravel index.php.

All you need is to add the following Nginx configuration into your Nginx virtual host:

location ^~ /filament {
try_files $uri $uri/ /index.php?$query_string;
}

Full example:

server {
listen 80;
listen [::]:80;
server_name example.com;
root /srv/example.com/public;
 
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
 
index index.php;
 
charset utf-8;
 
location / {
try_files $uri $uri/ /index.php?$query_string;
}
 
location ^~ /filament {
try_files $uri $uri/ /index.php?$query_string;
}
 
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
 
error_page 404 /index.php;
 
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
 
location ~ /\.(?!well-known).* {
deny all;
}
}

If you're not sure where to edit your Nginx file, mostly it's on /etc/nginx/sites-enabled/your-website-name.com.

You can read more at: Nginx Configuration for Filament and How to fix Laravel Filament assets are not loaded properly

avatar

Thanks 👍

avatar

Hi, this is not work in php8.3 with nginx php8.3-fpm .

avatar

Thanks It's work for me