原因:
请求的请求头参数有下划线,而Nginx代理默认会把header中参数有“_”下划线的参数去掉;解决这个问题只需要在Nginx的配置文件中添加:underscores_in_headers on; 默认为 off
k8s部署的 ingress-nginx 只需要在ingress-nginx-controller Configmap中添加 enable-underscores-in-headers: "true"
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
data:
access-log-path: /var/log/nginx/access.log
allow-snippet-annotations: "true"
compute-full-forwarded-for: "true"
enable-underscores-in-headers: "true"
error-log-path: /var/log/nginx/error.log
keep-alive-requests: "10000"
log-format-upstream: $remote_addr - $remote_user [$time_iso8601] $msec "$request"
$status $body_bytes_sent "$http_referer" "$http_user_agent" $request_length $request_time
[$proxy_upstream_name] [$proxy_alternative_upstream_name] [$upstream_addr] [$upstream_response_length]
[$upstream_response_time] [$upstream_status] $req_id
max-worker-connections: "65536"
kind: ConfigMap
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","data":null,"kind":"ConfigMap","metadata":{"annotations":{},"labels":{"app.kubernetes.io/component":"controller","app.kubernetes.io/instance":"ingress-nginx","app.kubernetes.io/name":"ingress-nginx","app.kubernetes.io/version":"1.2.0"},"name":"ingress-nginx-controller","namespace":"ingress-nginx"}}
creationTimestamp: "2022-06-11T06:44:16Z"
labels:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/version: 1.2.0
name: ingress-nginx-controller
namespace: ingress-nginx
resourceVersion: "1296033"
uid: eea7812a-2738-4e7d-b4f3-11041bec5dba