nginx的抓取客戶端真實IP的判斷腳本


root@nginx-01:/usr/local/nginx/conf/# cat proxyheader.conf 
if ( $proxy_add_x_forwarded_for ~ "^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})(.*)" ) {
    set $realip $1;
}
if ( $proxy_add_x_forwarded_for !~ "^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})(.*)" ) {
    set $realip $remote_addr;
}
if ( $http_ali_cdn_real_ip ~ "^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})" ) {
    set $realip $http_ali_cdn_real_ip;
}

 

nginx.conf中定義以下變量: 
    proxy_set_header Host $host;
    proxy_set_header acc_token $http_acc_token;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM