Laravel公用文件夹不受禁止
最近,我在我的Laravel项目中添加了一个CSS框架,该框架一直运行良好,直到我使用了一个图标集,可以在一个嵌套很深的文件夹中找到一个字体文件 我设置了Laravel Mix,将框架文件夹的目录复制到我的公共文件夹中,如下所示:Laravel公用文件夹不受禁止,laravel,Laravel,最近,我在我的Laravel项目中添加了一个CSS框架,该框架一直运行良好,直到我使用了一个图标集,可以在一个嵌套很深的文件夹中找到一个字体文件 我设置了Laravel Mix,将框架文件夹的目录复制到我的公共文件夹中,如下所示: .copyDirectory('node_modules/semantic ui css/themes'、'public/css/themes') 非常清楚的是,这些文件和它们的文件夹被完美地复制了,URL看起来匹配得很好。所有文件夹和文件似乎都具有正确的所有权和
.copyDirectory('node_modules/semantic ui css/themes'、'public/css/themes')
非常清楚的是,这些文件和它们的文件夹被完美地复制了,URL看起来匹配得很好。所有文件夹和文件似乎都具有正确的所有权和权限,与网站其他地方使用的相同
当导航到/css/themes/default/assets/font/icons.woff2
时,我会得到403,其中的文本“访问被拒绝”。如果我在/public/css
中创建自己的文件夹并向其中添加一个文件,则会发生这种情况,所有比/css
更深的内容都只是403
在这一点上,我相当确定问题要么是Nginx配置(部分如下所示),要么是我错过的Laravel本身的一些配置
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;
}
这一个让我感到困惑,在玩了它和谷歌搜索类似的问题后,我没有取得任何进展。任何帮助都将不胜感激。您的.htaccess文件应该是这样的 选项-多视图 和css文件的路径一样正常
<link href="{{ url('/') }}/css/custom.css" rel="stylesheet" type="text/css" />
将nginx位置拆分为两个不同的位置。这将允许nginx分别为资产和php文件提供服务:
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;
}
}
您是使用vhost还是cmd artisan serve来启动服务器?你检查过htaccess文件吗?@hamzanatek我正在使用vhost,它的设置反映了Nginx文档中推荐的设置。在.htaccess中是否有我应该特别查找的内容?我的印象是.htaccess文件在使用Nginx时没有任何作用,事实上我完全没有想到它。这个应该换成别的吗?太好了,搞定了。现在一切正常,谢谢。
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;
}
}