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;
}
没有使用CDN直接用$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; }
}


转自:https://hostloc.com/thread-1164027-1-1.html

感谢,【嗷嗷】大佬的教程

文章作者: Caesar
文章链接: https://pcnto.com/code/42-nginx-get-ip.html
版权声明: 本博客所有文章除特别声明外,转载请注明来自 Peng blog

如果您喜欢本站,你可以点击主页广告以示支持,谢谢。

广告是本站收益的来源希望您能够谅解。