Nginx+Tomcat无法正确获取的域名和ip地址

ngxin设置:

proxy_set_header Host $http_host;

代码片段如下:

server {
        listen       80;
        server_name  www.aso.ren;
        autoindex off;
        location / {
            root   /da/www/webapps;
            index  index.html index.jsp;
            proxy_pass       http://localhost:8080;

            proxy_redirect off;
            proxy_set_header  Host $http_host;
            proxy_set_header  X-Real-IP  $remote_addr;
            proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
        }
}

备注:

proxy_set_header  Host                    $http_host;            # 将当前Host头域值填充成客户端地址
proxy_set_header  X-Forwarded-Server      $host;  
proxy_set_header  X-Forwarded-For         $proxy_add_x_forwarded_for;    # 代理路由信息,此处取ip有安全隐患
proxy_set_header  X-Forwarded-Proto       $scheme;                      # 真实用户访问协议
proxy_set_header  X-Real-IP               $remote_addr;                # 真实用户IP
    原文作者:asoren
    原文地址: https://segmentfault.com/a/1190000009469553
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞