简单的Nginx反向代理似乎剥离了一些标题 [英] simple nginx reverse proxy seems to strip some headers

查看:121
本文介绍了简单的Nginx反向代理似乎剥离了一些标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是nginx的初学者.我在8080上有一个简单的Web服务器,我想将所有流量传递到这个相当小的环境中.我的代理似乎可以正常工作,只是自定义标头到达上游服务器时不存在.服务器块在下面.我需要在此添加些什么来保留我的自定义标头?在这种情况下,自定义标头是在angularjs中设置的,但我认为这与它无关,因为它可以很好地直接在服务器上运行到8080. ($ httpProvider.defaults.headers.common ['GH_client'] = client_id();)

I am a beginner at nginx. I have a simple webserver on 8080 that I want to pass all traffic to in this rather small environment. My proxy seems to work except that a custom header is not there when it gets to my upstream server. The server block is below. What would I need to add to this to keep my custom header? In this case the custom header was set in angularjs but I don't think that has anything to do with it as it works fine going directly to 8080 on the server. ($httpProvider.defaults.headers.common['GH_client'] = client_id();)

server {
server_name localhost;

location / {
        proxy_pass      http://localhost:8080;
        proxy_redirect  off;
    proxy_pass_header X-CSRF-TOKEN;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header   X-NginX-Proxy true;
}}

感谢您的帮助.

推荐答案

您的标头包含下划线(_).默认情况下,nginx威胁带有下划线的标头为无效,并将其删除.

Your header contains underscore (_). By default nginx threats headers with underscore as invalid and drops them.

您应启用 underscores_in_headers 指令.

You should enable underscores_in_headers directive.

否则,请考虑将标头名称更改为一个不带下划线的名称. GH-client将完全有效并代理到您的后端服务器.

Otherwise, consider change header name to one without underscores. GH-client will be perfectly valid and proxied to your backend server.

这篇关于简单的Nginx反向代理似乎剥离了一些标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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