diff --git a/script/docker/nginx/conf/nginx.conf b/script/docker/nginx/conf/nginx.conf index 4b9b179ed54d0885f771948eb586d56d52937fa0..ce62aaccf4bd727a3a4951fccf389113c0d7cae0 100644 --- a/script/docker/nginx/conf/nginx.conf +++ b/script/docker/nginx/conf/nginx.conf @@ -14,8 +14,11 @@ http { keepalive_timeout 65; # 限制body大小 client_max_body_size 100m; + client_body_buffer_size 128k; # 开启静态资源压缩 gzip_static on; + # 隐藏版本号 + server_tokens off; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' @@ -69,7 +72,24 @@ http { return 403; } + # hash 文件长缓存 + location ~* \.[a-f0-9]{8}\.(css|js)$ { + expires 1y; + add_header Cache-Control "public, immutable"; + } + + # 图片/字体缓存 + location ~* \.(jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf)$ { + expires 30d; + add_header Cache-Control "public"; + } + location / { + # HTML 页面不缓存 + add_header Cache-Control "no-cache, no-store, must-revalidate" always; + add_header Pragma "no-cache" always; + add_header Expires "0" always; + root /usr/share/nginx/html; # docker映射路径 不允许更改 try_files $uri $uri/ /index.html; index index.html index.htm;