我们在nginx.conf中已经有了这个设置了很长时间了。
sendfile on;
当我们更新了一个文件如/js/main.js并从浏览器https://test.com/js/main.js?newrandomtimestamp进行访问时,它仍然会加载旧版本,除非我们进行完全刷新(清除caching)从我们的浏览器。
但是当我们从sendfile改变设置的时候; 发送文件closures; 浏览器将加载更新文件的正确版本。
对于我们的生产Web服务器,我们应该使用sendfile; 或closures发送文件;? 如果发送文件; 是需要的(可能是为了更好的caching?更快的性能?)那么如何解决上述问题?
下面是我们的生产服务器中的nginx.conf,我们使用的是1.7.5版本:
user nginx; worker_processes 2; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 51200; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; client_max_body_size 8m; sendfile on; keepalive_timeout 65; real_ip_header X-Forwarded-For; set_real_ip_from 0.0.0.0/0; large_client_header_buffers 4 32k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/x-javascript application/javascript text/css application/xml application/json; gzip_vary on; include /etc/nginx/conf.d/*.conf; }