nginx 缓存配置
将index.html不缓存,其他资源文件缓存最大5天,也可以更长时间
#user nobody;
worker_processes 2;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_static on;
gzip_min_length 1024;
gzip_buffers 4 16k;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php application/vnd.ms-fontobject font/ttf font/opentype font/x-woff image/svg+xml;
gzip_vary off;
gzip_disable "MSIE [1-6]\.";
server {
listen 80;
charset utf-8;
location / {
root /usr/src/app;
index index.html index.htm;
try_files $uri $uri/ @rewrites;
if ($request_filename ~ .*\.(htm|html)$)
{
add_header Cache-Control no-cache,no-store,must-revalidate;
}
add_header Cache-Control public,max-age=432000;
}
location ~ ^/api {
rewrite ^/api(.*)$ $1 break;
proxy_pass http://192.168.1.99;
}
location @rewrites {
rewrite ^(.*)$ /index.html last;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
Last updated
Was this helpful?