Nginx replace REMOTE_ADDR with X-Forwarded-For

后端 未结 4 2016
逝去的感伤
逝去的感伤 2020-12-15 04:57

I am quite new to Nginx, and it seems all so confusing. I have my server setup perfectly, but the problem is, since my server is protected using a HTTP proxy; instead of log

4条回答
  •  误落风尘
    2020-12-15 05:42

    The correct way of doing this is by setting the real_ip_header configuration in nginx.

    Example with trusted HTTP proxy IP:

    set_real_ip_from 127.0.0.1/32;
    real_ip_header X-Forwarded-For;
    

    This way, the $_SERVER['REMOTE_ADDR'] will be correctly filled up in PHP fastcgi.

    Documentation link - nginx.org

提交回复
热议问题