simple nginx reverse proxy seems to strip some hea

2020-03-12 04:08发布

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;
}}

Thanks for any help.

1条回答
叼着烟拽天下
2楼-- · 2020-03-12 04:43

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

You should enable underscores_in_headers directive.

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

查看更多
登录 后发表回答