Reputation: 80
Recently I have added a CSS framework in to my Laravel project which has been working fine until I have gone to use an icon set which can be found as a font file in a deeply nested folder.
I set up Laravel Mix to copy the directory of the frameworks folder across to my public like so:
.copyDirectory('node_modules/semantic-ui-css/themes', 'public/css/themes')
To be perfectly clear, the files and their folders are being copied perfectly and the URL's seemingly match up just fine. All of the folders and files appear to have the correct ownership and permissions, the same that are being used elsewhere around the website.
When navigating to <domain>/css/themes/default/assets/fonts/icons.woff2
I get 403 with the text 'Access denied.', this also happens if I make my own folder in /public/css
and add a file to it, everything deeper than /css
simply 403's.
At this point I'm fairly sure that the problem is either the Nginx config (partially shown below) or some configuration of Laravel itself that I have missed.
location / {
try_files $uri $uri/ /index.php?$query_string;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
This one has me stumped and after playing around with it and googling for similar issues I have made no progress. Any help would be greatly appreciated.
Upvotes: 1
Views: 96
Reputation: 2106
Split nginx location in two different locations. This will allow nginx to serve assets and php files separately:
server {
listen 80;
server_name _;
index index.php;
root /path/to/your/public/directory;
rewrite ^(.+)/$ $1 permanent; # removing trailing slashes
# Location for all files, including assets
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# Location for php files
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Upvotes: 2
Reputation: 1549
Your .htaccess file should be like this Options -MultiViews
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$public /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
and the path of your css file as normal like
<link href="{{ url('/') }}/css/custom.css" rel="stylesheet" type="text/css" />
Upvotes: 0