修改nginx配置文件,直接在loacation模块下加入如下参数:
配置页面不缓存html和htm结尾的文件
if ($request_filename ~* .*\.(?:htm|html)$)
{
add_header Cache-Control "no-cache, no-store";
}
容器default.conf信息:文章来源:https://www.toymoban.com/news/detail-530512.html
root@nginx:/etc/nginx/conf.d# cat default.conf
upstream doctrans {
server doctrans-api:8080 max_fails=3 fail_timeout=30s weight=1;
}
server {
listen 80;
listen [::]:80;
server_name localhost;
absolute_redirect off;
client_max_body_size 200m;
location / {
root /usr/share/nginx/html/web;
index index.html index.htm;
if ($request_filename ~* .*\.(?:htm|html)$)
{
add_header Cache-Control "no-cache, no-store";
}
}
location /admin {
alias /usr/share/nginx/html/admin;
index index.html;
}
location ~ ^/(files|media)/ {
root /data/doctrans/;
expires 365d;
if ($request_filename ~* ^.*?\.(txt|pdf|doc|xls|ppt|docx|xlsx|pptx)$) {
add_header Content-Disposition: 'attachment;';
}
}
location /yeekitdoctrans {
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_redirect off;
proxy_pass http://doctrans$request_uri;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
break;
}
# location /6.2.0-123/ {
# proxy_pass http://doctrans-onlyoffice;
# }
# location /cache/ {
# proxy_pass http://doctrans-onlyoffice;
# }
# location /web-apps/ {
# proxy_pass http://doctrans-onlyoffice;
# }
}
root@nginx:/etc/nginx/conf.d#
该方法修改完之后,并不能立刻清理客户端当前的缓存,因为客户端当前的html页面还没有缓存 “不缓存配置”,就是当前的"no-cache, no-store"配置,改配置还没有缓存到客户端的浏览器中,有点绕,但是确实是这样的,需要清理一次缓存后,将次配置缓存到客户端后,才能生效,后面不再缓存。文章来源地址https://www.toymoban.com/news/detail-530512.html
到了这里,关于nginx配置前端不缓存的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!