【发布时间】:2019-10-10 02:53:28
【问题描述】:
我目前正在尝试使用 Docker 和 Nginx 设置 Laravel 6。
我通过 php-fpm 和 nginx 运行它,并且实际的应用程序加载得非常好。
我面临的问题是它找不到任何资产文件。
我的layout.blade.php顶部有一行
<link rel="stylesheet" type="text/css" href="{{ asset('css/app.css') }}" />
我可以看到该文件确实存在于文件夹中,但它总是在 Chrome 中得到 404。
我正在使用 Laravel 网站上的默认 nginx 配置,并进行了一些小的调整。
events {}
http {
server {
listen 80;
root /var/www/html/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php index.html index.htm;
charset utf-8;
location / {
try_files $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_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
}
直接导航到 url http://localhost/css/app.css 也会给我 Laravel 默认的 404 页面。
任何帮助将不胜感激!
我还可以进入容器,查看所有文件都在正确的目录中。
【问题讨论】:
-
有什么解决办法吗?