快乐的早安!我正在尝试完全缓存Node / Express应用程序。该网站很少改变,所以我很乐意拥有一个漂亮的字符串缓存机制。
如何设置看起来将应用程序(html,css,img,...)完全放入Nginx缓存(公共缓存)5分钟,因此页面从“Nginx缓存”“静态”服务,而Express -App baiscally idles?
我觉得这不是正确的设置:
proxy_cache_path /cache levels=1:2 keys_zone=my_cache:10m max_size=10g
inactive=60m use_temp_path=off;
server {
listen 80 default_server;
listen [::]:80 default_server;
location ^~ / {
proxy_cache my_cache;
proxy_pass http://localhost:3030;
}
}
答案 0 :(得分:0)
proxy_cache_path /cache levels=1:2 keys_zone=my_cache:100m max_size=10g inactive=5m use_temp_path=off;
server {
listen 80 default_server;
listen [::]:80 default_server;
location ^~ / {
proxy_cache my_cache;
proxy_pass http://localhost:3030;
# cache all requests of any type for 5m
proxy_cache_methods HEAD GET POST;
proxy_cache_valid any 5m;
expires 5m;
# default proxy cache key can be adjusted
proxy_cache_key $scheme$proxy_host$request_uri;
# set header - Host & Forwarded-For
proxy_set_header Host $host;
proxy_set_header Forwarded-For $proxy_add_x_forwarded_for;
# cache on first use
proxy_cache_min_uses 0;
}
}
随时了解nginx news