Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable cache nginx

Tags:

nginx

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;
    }
}
like image 879
Gfgj Ffji Avatar asked Aug 24 '17 09:08

Gfgj Ffji


People also ask

How do I disable NGINX cache in Cpanel?

To change the NGINX caching status for multiple users, select the checkbox next to the usernames you wish to change or select the checkbox above the table to select all visible users. Then, click Enable NGINX Cache or Disable NGINX Cache. To clear a user's cache, click Clear Cache next to the user's username.

Is NGINX cache enabled by default?

By default, NGINX Plus and NGINX serve cached content for as long as it is valid. Validity is configurable or can be controlled by the Cache-Control header set by the origin server.

How do I enable NGINX cache?

Go to the “Web Server” tab. In the “nginx settings” section, select the “Enable nginx caching” checkbox. (Optional) You can customize nginx caching settings. If you are not familiar with nginx caching, we recommend that you keep the default settings.

Where is the NGINX cache?

/var/cache/nginx – the path to the local disk directory for the cache. levels – defines the hierarchy levels of a cache, it sets up a two-level directory hierarchy under /var/cache/nginx.


1 Answers

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.

like image 82
Dayo Avatar answered Oct 13 '22 21:10

Dayo