Skip to main content

NGINX not passing all request headers to Tomcat [Resolved]

I have a CentOS system running NGINX with Tomcat behind it. NGINX has SSL enabled and is only used to push the connection to Tomcat. Pretty much everything is working just fine except certain request headers are not making it to Tomcat.

Our Java dev made a test page to print the request headers and here are the results so you can see what im talking about:

curl -H 'auth_token: some value' -H 'Host: demo-test.domain.com' http://127.0.0.1:8080/sjl.jsp
header.user-agent=curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
header.accept=*/*
header.auth_token=some value
header.host=demo-test.domain.com 

Above, you can see the request go directly to Tomcat, notice that the "auth_token" header is received.

Below is the 2nd request that goes to NGINX instead of Tomcat. Notice no "auth_token" header.

curl -H 'auth_token: some value' -H 'Host: demo-test.domain.com' -k https://127.0.0.1/sjl.jsp
header.host=demo-test.domain.com
header.connection=close
header.user-agent=curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
header.accept=*/* 

I tried to update the nginx.conf to set "proxy_pass_request_headers" to on, but it didn't seem to do anything. Here is the conf for the site in NGINX:

upstream demo-test.domain.com {
   ip_hash;   
   server demo-test.domain.com:8080; 
}

server {
    listen 80;
    listen [::]:80;
    server_name demo-test.domain.com www.demo-test.domain.com; 
    return 301 https://demo-test.domain.com$request_uri;
}

server {
   listen 443; 
   server_name demo-test.domain.com;

   location / {
      proxy_pass http://demo-test.domain.com;
      proxy_pass_request_headers on;
   }

   location /WebSocketServlet {
        proxy_pass http://demo-test.domain.com;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
     }
}

Please let me know if you see where my mistake is or can point me in the right direction. Having an issue getting this working. Thanks!


Question Credit: saleetzo
Question Reference
Asked March 17, 2019
Tags: nginx, tomcat
Posted Under: Unix Linux
68 views
2 Answers

Headers containing underscores are considered invalid by nginx, which is why it will not pass them by default. The behaviour can be overridden by the underscores_in_headers directive. For example:

underscores_in_headers on;

See this document for more.


credit: Richard Smith
Answered March 17, 2019

I am trying to pass all headers to nodejs. I have set even underscores_in_headers on;, still no luck.


credit: Prathibha Nag
Answered March 17, 2019
Your Answer