在http请求后端时,token是一种非常常见的使用方式,但是如果url请求参数不带token,或者请求头部不带token这样的请求应当直接返回401,而不要代理给后端服务器做处理了。可以有效降低后台服务器的负载。
location /api/ {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Content-Type, x-csrf-token, X-Access-Token, Accept';
add_header 'Access-Control-Allow-Methods' 'GET,HEAD,PUT,POST,DELETE,PATCH';
proxy_set_header X