flask用nginx代理后获取访问ip

  sre


ip=request.headers[‘X-Forwarded-For’]

#nginx

proxy_pass http://127.0.0.1:5000;
proxy_set_header X-Forwarded-For proxy_add_x_forwarded_for;
setReal http_x_forwarded_for;
if (Real ~ (\d+)\.(\d+)\.(\d+)\.(\d+),(.*) ){
    set Real1.2.3.4;
}
proxy_set_header X-Real-IpReal;
proxy_redirect off;

LEAVE A COMMENT

Captcha Code