网上搜搜连个像样的取ipv6代码也没有,这里写一个.如果有合法的http_x_forwarder_for就取第一或最后一个,没有则取直连IP.$ForwardedFirstIp 容易伪造,但可以做流量控制用$ForwardedLastIp 在前端代理可信情况下,可以做IP限制用http{#获取左边第一个
map $http_x_forwarded_for $ForwardedFirstIp {
default $remote_addr;
~^(?P[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[0-9a-fA-F]+:[0-9a-fA-F:]+:[0-9a-fA-F\.]+),?.*$ $firstAddr;
}
#获取右边第一个
map $http_x_forwarded_for $ForwardedLastIp {
default $remote_addr;
~,?(?P[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[0-9a-fA-F]+:[0-9a-fA-F:]+:[0-9a-fA-F\.]+)$ $lastAddr;
}}支持ipv4;支持ipv6缩写如 1080::8:800:200C:417A支持正常ipv6如 2409:8907:a125:2e4d:c5d:9d59:c2d5:a13a支
...
继续阅读
(127)