首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何关闭缓存nginx

如何关闭缓存nginx
EN

Stack Overflow用户
提问于 2017-08-24 17:07:44
回答 2查看 9.6K关注 0票数 5

远程类型被缓存,并显示新用户的非法ip。它有助于等待3-10秒或重启nginx。如何完全关闭缓存?

操作系统: Centos 7

nginx版本: nginx/1.10.2

代码语言:javascript
运行
复制
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
    worker_connections 1024;
}
http {
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    server {
        listen              80;
        server_name         test.mydomain.org;
        root                /etc/nginx/html;
        index   index.html;

        location / {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
            add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
            add_header 'Cache-Control' 'no-cache';
            default_type text/plain;
            return 200 "$remote_addr";
        }
        # Error page
        error_page  404    /404;
    }
}
EN

回答 2

Stack Overflow用户

发布于 2017-08-24 20:03:28

您看到的缓存来自浏览器缓存。将位置conf重置为包含后,清除浏览器缓存并尝试页面:

代码语言:javascript
运行
复制
    # kill cache
    add_header Last-Modified $date_gmt;
    add_header Cache-Control 'private no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
    if_modified_since off;
    expires off;
    etag off;

这绝对确保浏览器或任何中间代理不会缓存发送的输出。

票数 6
EN

Stack Overflow用户

发布于 2020-10-08 13:55:10

在nginx conf文件中使用此配置

代码语言:javascript
运行
复制
location /path-to-files/ {
directio 0;
}

这将绕过操作系统级缓存。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45857450

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档