嘿,
我是处理 NIGNX 服务器和 Linux 的新手。我的 HTML 文件已显示,但我的服务器未加载 CSS 文件。
我唯一发现的是这一行
包含/etc/nginx/mime.types;
我将其包含在 http block 中。
之后,我使用 sudo nginx -s reload
重新加载我的配置。可以肯定的是,我还执行了 sudo nginx -s stop
和 sudo nginx
。
这是我的整个配置:
http {
include /etc/nginx/mime.types;
server {
location / {
root /data/www;
}
location ~ \.(gif|jpg|png)$ {
root /data/www/images;
}
}
}
events {}
我的骨架文件位于/data/www。在此目录中还有另一个 CSS 文件夹。
提前谢谢您。
最佳答案
首先,您需要告诉 NGINX 让您的静态文件通过过期 header 获取 TTL(生存时间)。如果不存在,请在 NGINX 配置文件中找到它。使用 location
创建一个新指令
location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
expires 1s;
}
此后,继续从服务器中清除文件并强制其提供新文件。
- 在
nginx.conf
中关闭 sendfile - 在
mysite.conf
中设置过期时间为 1 秒 - 显式设置 Cache-Control header :
add_header Cache-Control no-cache;
当然,在执行上述操作之前。如果不需要采取严厉措施,请尝试手动删除缓存文件夹中的所有内容:/var/cache/nginx
如果这没有帮助,请继续执行此处列出的所有操作!
成功清除服务器上提供的静态文件后。将其添加到您的 NGINX 服务器 block 以实现优化。
gzip on;
gzip_comp_level 2;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain application/x-javascript text/xml text/css application/xml;
可以为不更改且定期提供的文件设置过期 header 。
location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
关于html - Nginx 服务器不从骨架框架加载 css 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42428946/