所以我有一个让Nginx为我的Laravel应用程序提供静态文件的问题。我可以在chrome的开发工具中看到请求正在到达这些文件所在的路径(http://mywebsite.com/public/css/style.css)。但他们根本没有被加载。我试图用很多方式让它工作,但它似乎并没有完成这项工作。任何人都可以帮助我吗?干杯!Laravel和Nginx的静态文件
server {
listen 80;
server_name mydomainname.com;
keepalive_timeout 70;
root /var/www/html/portfolio/public;
index index.php index.html index.htm index.nginx-debian.html;
autoindex on;
charset utf-8;
location/{
root /var/www/html/portfolio/public;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php$is_args$args;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/myapp-error.log error;
sendfile on;
client_max_body_size 100m;
rewrite^/index.php last;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ /\.ht {
deny all;
}
}
基本上,/ public目录中有很多文件没有加载,但应该是。比如css,js,角度模板等的html文件...
第一个红旗是“公开”,它不应该在那里(例如:'example.com/css/whatever.css')。 – Kyslik
你需要打开你的日志(nginx的)并阅读它。 500是最可能的权限问题,但读取日志,可能编辑问题并添加日志的尾部。如果它的404也查看laravels日志。另外,你是否通过......'public/index.php'访问你的页面? – Kyslik