nginx - realip module

最後更新: 2024-07-02

介紹

 

當 nginx 在 proxies 之後時, 透過 X-Forwarded-For 獲得 client real ip

它會修改 $remote_addr 為 X-Forwarded-For 的內容

$realip_remote_addr 為 connection 的 IP

 


Module: ngx_http_realip_module

 

 

查看有無 compile 此 module

nginx -V    # --with-http_realip_module

設定: realip.conf

set_real_ip_from  192.168.1.0/24;
real_ip_header    X-Forwarded-For;
real_ip_recursive on;

set_real_ip_from

address | CIDR

real_ip_header (Default: X-Real-IP)

由此 header 獲得 Client IP

e.g.  X-Real-IP | X-Forwarded-For

Notes

Cloudflare 使用 CF-Connecting-IP header field

real_ip_recursive (Default: off)

off: the last address sent in the request header field by trusted addresses(set_real_ip_from)

on: the last non-trusted address sent in the request header field

在 U22 Enable 它

ln -s /etc/nginx/conf-{available,enabled}/realip.conf

 

 

Creative Commons license icon Creative Commons license icon