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