2017-08-24 111 views
0

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

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; 
    } 
} 
+0

发布确切的错误消息和哪一行导致它? –

+0

没有错误,只是返回缓存中的旧IP。 –

+0

你如何测试它? –

回答

0

你所看到的缓存是从浏览器缓存。 清除浏览器缓存和重新定位的conf包括后尝试页:

# 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; 

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

+0

即时尝试此解决方案,不起作用 –

+0

然后要么你没有正确按照指示或在你的问题中缺少信息。 – Dayo

+0

nginx.conf https://pastebin.com/yWgT9twq +浏览器http请求http://6pic.ru/2017-08-24_174216.jpg –