熱評
加載中...
當前位置:首頁技術館建站教學服務器nginx的獲取ip的網頁

nginx的獲取ip的網頁

這是套了CF的用法($http_cf_connecting_ip)

nginx
location /ip {
add_header Content-Type text/plain;
return 200 $http_cf_connecting_ip;}

這是套了CDN(包括CF)/有反代($http_x_forwarded_for)

nginx
location /ip {
add_header Content-Type text/plain;
return 200 $http_x_forwarded_for;}

甚麼也沒套直接用$remote_addr

nginx
location /ip {
add_header Content-Type text/plain;
return 200 $remote_addr;}

也可以這樣(三個按順序匹配,你們就用這個吧)

nginx
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)

AngelaL博客

       本文是原創文章,採用CC BY-NC-SA 4.0協議,完整轉載請註明來自AngelaL博客

給TA打賞
共{{data.count}}人
人已打賞
服務器

檢測到CC攻擊自動開啟cloudflare5秒盾

2025-2-26 21:36:57

二開美化

【B2】問答模組新增OpenAI ChatGPT機器人自動回答功能

2025-2-23 2:36:09

0 條回复 A文章作者 M管理员
    
    暫無討論,說說你的看法吧
個人中心
購物車
優惠劵
今日簽到
有新私信 私信列表
搜索