会话丢失-NGINX配置之underscores_in_headers

1.描述

问题

NGINX代理某个web服务时,单机情况下也出现不停的要求认证的情况

初步分析

去掉NGINX代理,直接访问服务,未出现上述情况;

进一步分析:
查看经过NGINX的请求和直接访问服务请求区别:
cookie中的部分带下划线’_'的认证信息丢失导致,因此出现重复要求认证。

2.解决办法

在NGINX,配置文件http {} 模块中添加如下配置:

underscores_in_headers on;

重启NGINX服务,再次访问服务正常。

3.官方解释

Syntax: underscores_in_headers on | off;
Default: underscores_in_headers off;
Context: http, server

Enables or disables the use of underscores in client request header fields. When
the use of underscores is disabled, request header fields whose names contain underscores
are marked as invalid and become subject to the ignore_invalid_headers directive.

由官方解释可以看出,默认情况下,underscores_in_headers为off,表示当客户端请求头中带有下划线的字段默认将会被标识为无效字段。

因此,如下两个建议:

  • 尽量不要在请求头中添加带下划线的字段;
  • 使用NGINX代理的时候,添加underscores_in_headers on的配置。
  • 8
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值