From a12af6b05e2a400830a0873ef15dee7a74700111 Mon Sep 17 00:00:00 2001 From: Chika Date: Wed, 6 Apr 2022 15:12:55 +0300 Subject: [PATCH] nginx: enable cache for static files --- nginx.conf | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/nginx.conf b/nginx.conf index 46d70ec..8134407 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,8 +1,22 @@ server { - listen 3000; - location / { + listen 3000; root /usr/share/nginx/html; - index index.html index.htm; - try_files $uri $uri/ /index.html =404; - } -} \ No newline at end of file + + location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|mp3|ogg|ogv|webm|htc|woff2|woff)$ { + expires 1M; + access_log off; + # max-age must be in seconds + add_header Cache-Control "max-age=2629746, public"; + } + + location ~* \.(?:css|js)$ { + expires 1M; + access_log off; + add_header Cache-Control "max-age=2629746, public"; + } + + location / { + index index.html index.htm; + try_files $uri $uri/ /index.html =404; + } +} \ No newline at end of file