我有用于服务器生成的缓存的简单位置:
location /api/get-hloc {
#add acccess-allow headers
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
#try cached files
root /dev/shm/get-hloc/;
try_files /$arg_hash.hloc /stocks/graphics/get-iis-graphic?$args;
}
Run Code Online (Sandbox Code Playgroud)
它能做什么?它只是检查内存中是否有可以为请求提供服务的文件,如果没有文件,则尝试实际为将来的请求生成文件的位置并将其提供给客户端。
add_header
除了被忽略的指令外,一切都按预期工作。
是否可以在尝试 try_files 中的新位置之前添加标头,或者我应该仅在端点位置添加标头?