6

The remote type is cached and displays an illegal ip for the new user. It helps wait 3-10 seconds or restart nginx. How to completely turn off caching?
OS: Centos 7
nginx version: nginx/1.10.2

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;
    }
}
15
  • Post the exact error message and which line is causing it? Commented Aug 24, 2017 at 9:20
  • There is no error, just returns the old ip, which is in the cache. Commented Aug 24, 2017 at 9:22
  • How are you testing it? Commented Aug 24, 2017 at 9:22
  • use proxy and see on myip.com / myip.ru (see proxy ip), and my site (old ip). If restart nginx, im see proxy ip Commented Aug 24, 2017 at 9:27
  • Use a new incognito browser to check your page or use curl. Don't use browser as it will cache the page Commented Aug 24, 2017 at 9:30

2 Answers 2

11

The caching you are seeing is from the browser cache. Clear the browser cache and try the page after resetting the location conf to include:

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

This makes absolutely sure the browser or any intermediate proxy will not cache the output sent.

Sign up to request clarification or add additional context in comments.

3 Comments

nginx.conf pastebin.com/yWgT9twq + browser http request 6pic.ru/2017-08-24_174216.jpg
I have implemented your config on my server and it works fine every single time. No issues even without disable cache in network tab
How you test? Browser with activated proxy/tor (not incognito), open site, change ip (not close browser), refresh page
0

use this configuration in nginx conf file

location /path-to-files/ {
directio 0;
}

which will bypass OS level cache.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.