limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;

server
{
....

location /api/ {
error_page 503 =200 /dealwith_503?callback=$arg_callback;
limit_req zone=one burst=4 nodelay;
proxy_pass http://127.0.0.1:7773/api/;
}

location /dealwith_503{
add_header Content-Type 'text/html; charset=utf-8';
set $ret_body '{"code": "400","msg": "操作太频繁了,请坐下来喝杯茶。"}';
if ( $arg_callback != "" )
{
return 200 'try{$arg_callback($ret_body)}catch(e){}';
}
return 200 $ret_body;
}
...

其他

location ^~ /websocket {
proxy_pass http://127.0.0.1:7773/websocket;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 600s;
}

}

最后修改:2021 年 03 月 10 日
如果觉得我的文章对你有用,请随意赞赏