-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
67 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
cp /dist/vhosts/* /etc/nginx/conf.d/ | ||
cp /dist/conf/* /usr/local/openresty/nginx/conf/ | ||
nginx -s reload | ||
|
||
# Write start info to ngxway.start.log and fix this bug : https://github.com/WGrape/ngxway/issues/4 | ||
time=$(date "+%Y-%m-%d %H:%M:%S") | ||
if [ $? -ne 0 ]; then | ||
log="[${time}] >>>>>>>>failed to start ngxway<<<<<<<<" | ||
echo -e $log | ||
echo $log >> /dist/logs/ngxway.start.log | ||
exit 1 | ||
else | ||
log="[${time}] start ngxway success" | ||
echo -e $log | ||
echo $log >> /dist/logs/ngxway.start.log | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,36 @@ | ||
-- https://blog.csdn.net/carlos__z/article/details/112208972 | ||
-- https://blog.csdn.net/knight_zhou/article/details/122495234 | ||
-- https://blog.openresty.com.cn/cn/edge-cache-rules/ | ||
-- https://github.com/openresty/lua-resty-limit-traffic | ||
local limit_req = require "resty.limit.req" | ||
|
||
-- limit the requests under 200 req/sec with a burst of 100 req/sec, | ||
-- that is, we delay requests under 300 req/sec and above 200 | ||
-- req/sec, and reject any requests exceeding 300 req/sec. | ||
local lim, err = limit_req.new("my_limit_req_store", 200, 100) | ||
if not lim then | ||
ngx.log(ngx.ERR, "failed to instantiate a resty.limit.req object: ", err) | ||
return ngx.exit(500) | ||
end | ||
|
||
-- the following call must be per-request. | ||
-- here we use the remote (IP) address as the limiting key | ||
local key = ngx.var.binary_remote_addr | ||
local delay, err = lim:incoming(key, true) | ||
if not delay then | ||
if err == "rejected" then | ||
return ngx.exit(503) | ||
end | ||
ngx.log(ngx.ERR, "failed to limit req: ", err) | ||
return ngx.exit(500) | ||
end | ||
|
||
if delay >= 0.001 then | ||
-- the 2nd return value holds the number of excess requests | ||
-- per second for the specified key. for example, number 31 | ||
-- means the current request rate is at 231 req/sec for the | ||
-- specified key. | ||
local excess = err | ||
|
||
-- the request exceeding the 200 req/sec but below 300 req/sec, | ||
-- so we intentionally delay it here a bit to conform to the | ||
-- 200 req/sec rate. | ||
ngx.sleep(delay) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters