Home > database >  How do I disable caching in an Nginx reverse proxy?
How do I disable caching in an Nginx reverse proxy?

Time:05-09

Will it have caching behavior by default in the reverse proxy configuration below?

location / {
    proxy_pass http://12.23.45.78:8080;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host $host;
    add_header Cache-Control no-store;
    add_header Pragma no-cache;
}

As I understand it, to support caching, the proxy_cache parameter needs to be added. Does this mean that if this parameter is not added, the content is not cached by default?

I would like to not cache the back-end response content on the reverse proxy server, do I need to add other settings to achieve this? Or is this enough for now?

Also is it necessary to keep the following two lines? It seems to tell the visitor's browser not to cache the content, but does it also tell the reverse proxy host not to cache the content (doubtful)? This confuses me ...

add_header Cache-Control no-store;
add_header Pragma no-cache;

CodePudding user response:

By default proxy_cache is off, so you won't have any unwanted cache behavior. Also you may want to check logs to be completely sure, as far as I know, nginx tries to cache files if their size exceeds its buffer config directives.

And your directives:

add_header Cache-Control no-store;
add_header Pragma no-cache;

is completely another story, it's browser client side, not nginx (server).

  • Related