信息

【技术分享】nginx获取ip的网页

这是套了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_addr

location /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)

🌟-阅读剩余-🌟
版权声明 1、本网站名称:安鹿轩
2、本站永久网址:https://www.anlu1314.com
3、本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系在本站私信站长进行删除处理。
4、本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
6、本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。

THE END