[ol]location /ip {
add_header Content-Type text/plain;
return 200 $http_cf_connecting_ip;}[/ol]复制代码
这是套了CDN(包括CF)/有反代($http_x_forwarded_for)
[ol]location /ip {
add_header Content-Type text/plain;
return 200 $http_x_forwarded_for;}[/ol]复制代码
啥也没套直接用$remote_addr
[ol]location /ip {
add_header Content-Type text/plain;
return 200 $remote_addr;}[/ol]复制代码
也可以这样(三个按顺序匹配,你们就用这个吧)
[ol]location /ip {
add_header Content-Type text/plain;
if ($http_cf_connecting_ip != ""){return 200 $http_cf_connecting_ip;}
if ($http_x_forwarded_for != ""){return 200 $http_x_forwarded_for;}
if ($remote_addr != ""){return 200 $remote_addr;}}[/ol]复制代码
加在你的网站配置里就行了,/ip可以自己改成想要的
支持ipv4/ipv6(但示例没解析ipv6)
示例 haoduck.com/ip