V
V
Vlad2017-01-26 12:40:06
Nginx
Vlad, 2017-01-26 12:40:06

How does Nginx caching work?

Enabled caching for files on the server in the nginx.conf file

location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf|woff2)$ {
      root /var/www/cheats/data/www/site.ru;
      access_log /var/www/httpd-logs/site.ru.access.log ;
      access_log /var/www/nginx-logs/cheats isp;
      expires 60d;
    }

1) What is happening now? Are all files of the listed formats saved in some folder on the server and loaded from there?
2) If I change one of the files, then the visitor will see the updated file only after 60 days?? Or not? Can you reset the cache somehow?
3) Should I cache .html files? What then? Will the comments under the article be updated once a month?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Ukolov, 2017-01-26
@alexey-m-ukolov

  1. The files are saved in the user's browser because the expires directive controls the regular cache http headers ( nginx.org/en/docs/http/ngx_http_headers_module.html).
  2. Yes, you can reset the cache only by changing the file name.
  3. Worth it if they rarely change. Comments can be loaded via js from a separate non-cached url, while the page itself can be cached for a long time.

K
Konstantin B., 2017-01-26
@Kostik_1993

If you really want to cache a dynamic content, then you can look towards Varnish + ESI

S
sector67, 2017-02-28
@sector67

Thanks, Full Fast KVM VPS 2017 config (Frontend Nginx 1.11.10 + Backend Apache 2.4 PHP (5/7) + VestaCP) pastebin.com/v0VKjKXW

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question