我们有一个FreeBSD OS系统,一个nginx网络服务器和php-fpm作为PHP CGI.有时.js和.css文件仅部分加载,缺少文件末尾约5-7个字,因此我们的网站外观出现问题,因为它成为部分加载javascript或css文件的丑陋原因.我们试图禁用gzip,但是它没有帮助我们.通常,这是在我们上传修改后的CSS或JavaScript文件后发生的.
Nginx版本:0.7.65
Nginx配置:
worker_processes 100;
worker_priority -5;
worker_rlimit_nofile 51200;
events {
worker_connections 51200;
use kqueue;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] ' '"$request_filename" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent" "$http_x_forwarded_for"';
server_names_hash_bucket_size 512;
sendfile on;
tcp_nopush on;
keepalive_timeout 70 30;
send_timeout 30s;
reset_timedout_connection on;
resolver 127.0.0.1;
resolver_timeout 10s;
server_tokens off;
client_max_body_size 5m;
open_file_cache max=100000 inactive=40s;
open_file_cache_valid 60s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
#gzip on;
…………………
…………………
我希望这部分配置足以为我们提供帮助.
最佳答案
此问题是open_file_cache的结果.
原因
open_file_cache通过比较文件的inode来测试文件是否已更改.当您在适当位置更改文件时,Nginx不会注意到更改,并返回旧内容.并且由于open_file_cache对于每个Nginx的工作程序都是本地的,因此它可能返回正确的新连接或旧内容,具体取决于正在处理请求的工作程序.
解决方法
您不应该将其用于内容更改的文件(将其关闭以用于特定位置:open_file_cache关闭),也不要按照akira的建议进行原子文件更新(使用mv
或rename
).