1
1
1
https://en.wikipedia.org/wiki/Normalization_(statistics)
https://en.wikipedia.org/wiki/Standard_score
https://en.wikipedia.org/wiki/Feature_scaling
https://en.wikipedia.org/wiki/Coefficient_of_variation
https://www.cnblogs.com/feiyumo/p/9866818.html
https://blog.csdn.net/binlin199012/article/details/84638649归一化:normalization
Z分数:Z-score
特征缩放:Feature scaling
变异系数:Coefficient of variationIn statistics and applications of statistics, normalization can have a range of meanings.
In the simplest cases, normalization of ratings means adjusting values measured on different scales to a notionally common scale, often prior to averaging.
In more complicated cases, normalization may refer to more sophisticated adjustments where the intention is to bring the entire probability distributions of adjusted values into alignment.
归一化是一种简化计算的方式,即将有量纲的表达式,经过变换,化为无量纲的表达式,成为标量。意义:一个给定的值距离平均数多少个标准差?
意义:将不同特征的值量化到同一区间。
意义:离散程度的归一化,用于比较两组数据离散程度的大小。
https://www.cnblogs.com/zhenyuyaodidiao/p/9288430.html
https://openresty.org/download/agentzh-nginx-tutorials-zhcn.html
https://www.cnblogs.com/jackey2015/p/10375549.htmlNginx 处理请求的过程一共划分为 11 个阶段,按照执行顺序依次是 post-read、server-rewrite、find-config、rewrite、post-rewrite、preaccess、access、post-access、try-files、content 以及 log.
所谓“内部跳转”,就是在处理请求的过程中,于服务器内部,从一个 location 跳转到另一个 location 的过程。
既然是内部跳转,当前正在处理的请求就还是原来那个,只是当前的 location 发生了变化,所以还是原来的那一套 Nginx 变量的容器副本。echo_exec 指令和 rewrite 指令可以发起“内部跳转”。这种跳转会自动修改当前请求的 URI,并且重新匹配与之对应的 location 配置块,再重新执行 rewrite、access、content 等处理阶段。因为是“内部跳转”,所以有别于 HTTP 协议中定义的基于 302 和 301 响应的“外部跳转”,最终用户的浏览器的地址栏也不会发生变化,依然是原来的 URI 位置。
而 ngx_index 模块一旦找到了 index 指令中列举的文件之后,就会发起这样的“内部跳转”,仿佛用户是直接请求的这个文件所对应的 URI 一样。最先执行的 post-read 阶段在 Nginx 读取并解析完请求头(request headers)之后就立即开始运行。
支持 Nginx 模块注册处理程序。比如标准模块 ngx_realip 就在 post-read 阶段注册了处理程序。post-read 阶段之后便是 server-rewrite 阶段。
当 ngx_rewrite 模块的配置指令直接书写在 server 配置块中时,基本上都是运行在 server-rewrite 阶段。紧接在 server-rewrite 阶段后边的是 find-config 阶段。
这个阶段并不支持 Nginx 模块注册处理程序,而是由 Nginx 核心来完成当前请求与 location 配置块之间的配对工作。
换句话说,在此阶段之前,请求并没有与任何 location 配置块相关联。因此,对于运行在 find-config 阶段之前的 post-read 和 server-rewrite 阶段来说,只有 server 配置块以及更外层作用域中的配置指令才会起作用。运行在 find-config 阶段之后的便是我们的老朋友 rewrite 阶段。rewrite 阶段再往后便是所谓的 post-rewrite 阶段。
这个阶段也像 find-config 阶段那样不接受 Nginx 模块注册处理程序,而是由 Nginx 核心完成 rewrite 阶段所要求的“内部跳转”操作(如果 rewrite 阶段有此要求的话)。运行在 post-rewrite 阶段之后的是所谓的 preaccess 阶段。
标准模块 ngx_limit_req 和 ngx_limit_zone 就运行在此阶段,前者可以控制请求的访问频度,而后者可以限制访问的并发度。运行在 preaccess 阶段之后的则是我们的另一个老朋友,access 阶段。
标准模块 ngx_access、第三方模块 ngx_auth_request 以及第三方模块 ngx_lua 的 access_by_lua 指令就运行在这个阶段。access 阶段之后便是 post-access 阶段。紧跟在 post-access 阶段之后的是 try-files 阶段。
这个阶段专门用于实现标准配置指令 try_files 的功能,并不支持 Nginx 模块注册处理程序。Nginx 的 content 阶段是所有请求处理阶段中最为重要的一个,因为运行在这个阶段的配置指令一般都肩负着生成“内容”(content)并输出 HTTP 响应的使命。local host = "192.168.16.2"
local port = 6379
function getClientIp()
local headers = ngx.req.get_headers()
local ip = headers["X-Real-IP"]
if ip == nil then
ip = headers["X-Forwarded-For"]
end
if ip == "unknown" or ip == nil then
ip = ngx.var.remote_addr
end
if ip == nil then
ip = "0.0.0.0"
end
return ip
end
function ipDeny()
local ip = getClientIp()
local redis = require "resty.redis"
local red = redis:new()
red:set_timeouts(1000, 1000, 1000) -- 1 sec
local ok, err = red:connect(host, port)
if not ok then
ngx.say("failed to connect: ", err)
return
end
isDeny, err = red:sismember("ip_blacklist", ip)
return isDeny
end
function countQueue()
local redis = require "resty.redis"
local red = redis:new()
red:set_timeouts(1000, 1000, 1000) -- 1 sec
local ok, err = red:connect(host, port)
if not ok then
ngx.say("failed to connect: ", err)
return
end
count, err = red:incr("num")
return count
end
function read(filename)
local path = "/etc/nginx/conf.d"
local file = io.open(path..'/'..filename,"r")
if file == nil then
return
end
t = {}
for line in file:lines() do
table.insert(t,line)
end
file:close()
return t
end
function uaFilter()
local rules = read("user-agent")
local ua = ngx.var.http_user_agent
if ua == nil then
ngx.exit(403)
end
for _, rule in pairs(rules) do
if rule ~= "" and ngx.re.match(ua,rule,"isjo") then
ngx.exit(403)
end
end
return
end