proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Posted hixiaowei
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;相关的知识,希望对你有一定的参考价值。
1.nginx 配置模板
server { listen 80; client_max_body_size 512M; proxy_set_header Connection ""; proxy_http_version 1.1; proxy_connect_timeout 300; proxy_read_timeout 300; access_log /var/log/nginx/ralph-access.log; error_log /var/log/nginx/ralph-error.log; location /static { alias /usr/share/ralph/static; access_log off; log_not_found off; expires 1M; } #location /media { # alias /var/local/ralph/media; # add_header Content-disposition "attachment"; #} location / { proxy_pass http://127.0.0.1:8000; include /etc/nginx/uwsgi_params; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
如果想要通过X-Forwarded-For获得用户ip,就必须先使用proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 这样就可以获得用户真实ip。
参考: https://blog.51cto.com/gyj110/2056933
以上是关于proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;的主要内容,如果未能解决你的问题,请参考以下文章
Nginx指令add_header和proxy_set_header的区别