无法从 NGINX 获取包含句点的标头 [英] Cannot get header that contains a period from NGINX

查看:20
本文介绍了无法从 NGINX 获取包含句点的标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"Abp.TenantId"null 因为 ".".

如果去掉"."(比如"AbpTenantId"),就可以了.

如何添加带有"."的标题?

======================================================

localhost 调试:

  1. 显示临时标头(根据客户请求显示)
  2. Request.Headers.Unknown(在服务器、api 操作中显示)
  3. Request.Headers.MaybeUnknown(在服务器、api 操作中显示)

localhost 没问题.

服务器中的相同代码,但服务器错误.

tenantId 的代码:

日志没有tenantId,所以报错:

localhost 没问题:

服务器故障:

解决方案

Nginx 作为反向代理不会传递包含句点的标题.

ABP 4.4+

TenantIdResolveKey 是可配置的:

Configuration.MultiTenancy.TenantIdResolveKey = "Abp-TenantId";

低于 ABP 4.4

您可以在 Nginx 中关闭忽略无效"标头:

<块引用>

语法:ignore_invalid_headers on |离开;默认值:ignore_invalid_headers on;上下文:http、服务器

控制是否应忽略具有无效名称的标题字段.有效名称由英文字母、数字、连字符和可能的下划线组成(由 underscores_in_headers 指令控制).

如果指令是在服务器级别指定的,则仅当服务器是默认服务器时才使用其值.指定的值也适用于侦听相同地址和端口的所有虚拟服务器.

The header "Abp.TenantId" is null because of the ".".

If remove the "." (like "AbpTenantId"), it will be ok.

How to add a header with a "."?

=======================================================

localhost debug:

  1. Provisional headers are shown (show this on client request)
  2. Request.Headers.Unknown (show this in server, api action)
  3. Request.Headers.MaybeUnknown (show this in server, api action)

localhost is ok.

The same code in server, but server error.

The code for the tenantId:

The logs have no tenantId, so error:

localhost is ok:

Server fail:

解决方案

Nginx as a reverse proxy will not pass headers that contain a period.

ABP 4.4+

TenantIdResolveKey is configurable:

Configuration.MultiTenancy.TenantIdResolveKey = "Abp-TenantId";

Below ABP 4.4

You can turn off ignore "invalid" headers in Nginx:

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

Controls whether header fields with invalid names should be ignored. Valid names are composed of English letters, digits, hyphens, and possibly underscores (as controlled by the underscores_in_headers directive).

If the directive is specified on the server level, its value is only used if a server is a default one. The value specified also applies to all virtual servers listening on the same address and port.

这篇关于无法从 NGINX 获取包含句点的标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆