NLB后面的$http_x_forwarded_proto ElasticBeanstalk Tomcat的NGINX协议头为空

omvjsjqw  于 2023-08-03  发布在  Nginx
关注(0)|答案(1)|浏览(106)

这是我的.platform/nginx/conf.d/elasticbeanstalk/00_application.conf,它肯定能正常工作,因为我能很好地获取客户端的主机。但是$http_x_forwarded_proto为null。

location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
    proxy_set_header X-Request-URI $request;
    proxy_set_header X-Request-PATH $request_uri;
    proxy_set_header Host $http_host;
    proxy_pass http://127.0.0.1:8080;
    proxy_http_version  1.1;

}
client_max_body_size 20M;

字符串

4ngedf3f

4ngedf3f1#

确保填充**$http_x_forwarded_proto头的解决方案包括两个步骤:
1.编辑NLB目标组的属性,并确保启用
Proxy protocol v2属性
1.编辑nginx.conf文件,插入
proxy_protocol**如下:

server {
    listen        80 default_server proxy_protocol;
    access_log    /var/log/nginx/access.log main;

    client_header_timeout 60;
    client_body_timeout   60;
    keepalive_timeout     60;
    .
    .
    .
    # Include the Elastic Beanstalk generated locations
    include conf.d/elasticbeanstalk/*.conf;
}

字符串
可以将nginx.conf文件放在项目的Web根文件夹的**.platform/nginx/nginx.conf**中

相关问题