简体   繁体   English

我如何将非标准应用程序特定的 header 从 nginx 转发到我的应用程序服务器?

[英]How may I forward a non standard application specific header from nginx to my application server?

I have not been able to pass an application specific header to my application that is running on uWSGI and Flask我无法将特定于应用程序的 header 传递给我在 uWSGI 和 Flask 上运行的应用程序

This is from my nginx.conf这是来自我的 nginx.conf

                proxy_pass http://localhost:5000/;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $host;
                proxy_set_header X-NginX-Proxy true;
                proxy_pass_request_headers on;
                proxy_set_header $HTTP_Chart-Type $http_chart_type;
        }

These are my headers from chrome:这些是我来自 chrome 的标题:

Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cache-Control: no-cache
chart_type: line

I am trying to pass the chart_type header to my backend.我正在尝试将 chart_type header 传递到我的后端。

Thanks谢谢

The default value of proxy_pass_request_headers is on , so there should be no need to explicitly set it (unless it is turned off in the config somewhere and that has an effect on your configuration). proxy_pass_request_headers的默认值是on ,因此不需要显式设置它(除非它在某处的配置中被关闭并且对您的配置有影响)。

With the default setting ( on ), Nginx passes all headers to the backend, so you don't need any special configuration to pass a custom header (assuming your http_chart_type is a custom header).使用默认设置 ( on ),Nginx 将所有标头传递到后端,因此您不需要任何特殊配置即可传递自定义 header(假设您的http_chart_type是自定义标头)。

Your problems passing the http_chart_type header from Nginx to the backend is likely related to Nginx by default not allowing header names with underscore.您将http_chart_type header 从 Nginx 传递到后端的问题可能与 Nginx 默认情况下不允许带有下划线的 header 名称有关。 See https://stackoverflow.com/a/74798560/3571 .请参阅https://stackoverflow.com/a/74798560/3571

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将请求 IP 从 NGINX 转发到 node.js 应用程序? - How to forward request IP from NGINX to node.js application? 根据 Nginx 上的主机 header 代理传递/转发请求到特定服务器 - Proxy pass / Forward request to specific server according to the Host header on Nginx nGINX读取标头并将其传递到其他应用程序服务器 - nGINX read Header & Pass it to different Application Server 如何将url参数从Nginx转发到服务器的API,以便允许/禁止用户查看某些文件? - How to forward url parameters from Nginx to my server's API so I can allow/disallow users to view certain files? 我如何使用 nginx 作为 angular 6 应用程序的服务器? - How I can use nginx as server for angular 6 application? 如何将流量从 Nginx 入口路由到应用程序 Tomcat 服务器 - How to route traffic from Nginx ingress to an application Tomcat server 在Nginx ruby​​ on rails上进行热补丁期间,我可以通过服务器重新启动来重新加载特定文件而不是整个应用程序吗? - During hot patch in nginx ruby on rails can I reload the specific file instead of whole application by server restart? Nginx不缓存我的应用程序 - Nginx not Caching my Application 如何设置NGINX按header转发? - How to set NGINX to forward by header(s)? 将标头从nginx传递到运行Flask应用程序的uWSGI后端 - Pass a header from nginx to uWSGI backend running a Flask application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM