nginx返回403 forbidden

在将Elasticsearch从5升级到7的过程中,遇到一个问题:通过nginx转发_Bulk请求时返回403状态码。问题在于Elasticsearch7的安全配置比5更严格。解决方案是在nginx配置中添加`proxy_set_header Host $http_host;`,此改动后,测试显示问题已得到解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在elasticsearch5升级到elasticsearch7的过程中。由于同一台机器启动了es5和es7的两个不同端口。
而业务在执行导入操作到时候,前端发送es _bulk请求到业务处理服务器,然后nginx拦截_bulk请求直接proxy_pass转发到elasticsearch7。在nginx转发_bulk请求过程中,发现在nginx那里日志返回403状态码。
未更改前的配置

server {
        listen 80;

        server_name xxx.xxx.xxx;
        access_log  /data/nginx/xxx.log;
	#....其他配置省略
    location ~ ^/_bulk {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://${eshost}:${port};
    }

问题在于之前elasticsearch5的时候,上面的配置是ok的。反而升到es7的时候却返回403了。或许原因在于es7的鉴权、安全保障方面上确实比较严格。

解决的办法

在上述配置添加上proxy_set_header Host $http_host;

    location ~ ^/_bulk {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        #添加这一句
        proxy_set_header Host $http_host;
        proxy_pass http://172.16.176.111:9207;
    }

综上,测试的时候问题的可以得到解决了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值