码迷,mamicode.com
首页 > 其他好文 > 详细

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

时间:2019-05-02 18:51:39      阅读:439      评论:0      收藏:0      [点我收藏+]

标签:51cto   code   color   nginx 配置   connect   proxy   etc   size   pass   

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;

标签:51cto   code   color   nginx 配置   connect   proxy   etc   size   pass   

原文地址:https://www.cnblogs.com/hixiaowei/p/10802719.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!