首页 技术 正文
技术 2022年11月21日
0 收藏 321 点赞 3,918 浏览 1608 个字

最近开发的时候,调整js时会一直使用缓存文件,无法显示改动!
nginx配置静态文件add_header Cache-Control no-cache;也不起作用,很苦恼!

nginx配置代码:
events {
worker_connections 768;
# multi_accept on;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;
gzip_disable “msie6”;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

具体配置的server代码:
server {
listen 80 ;
server_name tp.co admin.tp.co;
root /code/think/public;

index index.php;
location ~.*\.(js|css|png|jpg)$
{
root /code/think;
add_header Cache-Control no-cache;
}
location / {
if (!-d $request_filename) {
rewrite ^/(.*)/(.*)/*$ /index.php?m=$1&a=$2 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ \.php { #去掉$
fastcgi_pass unix:/run/php/php7.1-fpm.sock;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(.*)$; #添加
fastcgi_param PATH_INFO $fastcgi_path_info; #添加
}

}

网上找了一下资料终于解决了!使用virtualBox虚拟机,安装的nginx,不管怎么修改js,css文件,怎么强制刷新设置不缓存,都不管用,原因在于sendfile on;;这个配置在nginx.conf,将sendfile on;改为sendfile off;;再ctrl+F5,OK!完美解决!!

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,912
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,437
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,252
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,063
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,694
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,732