📜 ⬆️ ⬇️

Cheat Sheet: Caching Images, CSS and JS in NGINX

Note for those who are not experts in NGINX, and the problem must be solved quickly.

Let's say you have NGINX on your server and you want all the static to be cached on the client. In the NGINX host config, list this:

server {
listen 80;
server_name mysite.com;
# ( )
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|pdf|ppt|txt|bmp|rtf|js)$ {
root /path/to/document/root/; #
access_log off; #
expires 3d; # 3

You can check it in FireBug in the NET tab: refresh the page 2 times and look at the response code. If 200 is OK, then it does not work. If 304 Not Modified, then it works.
Not bad speeds up the site.

Source: https://habr.com/ru/post/105716/

All Articles