【发布时间】:2017-06-22 11:25:30
【问题描述】:
所以我在让 Nginx 为我的 Laravel 应用程序提供静态文件时遇到了问题。我可以在 chrome 的开发工具中看到请求是对路径发出的,这些文件应该在哪里(http://mywebsite.com/public/css/style.css)。但它们根本没有被加载。我已经尝试过以多种方式让它工作,但它似乎并没有完成这项工作。有人可以帮我吗?干杯!
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)。 -
你需要打开你的日志(nginx 的)并阅读它。 500 很可能是权限问题,但请阅读日志,可能编辑问题并添加日志尾部。如果它的 404 也看看 laravel 日志。另外,您是否通过...
public/index.php访问您的页面?