3

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!

  • Can you add the debugging log of nginx? – heemayl Jul 19 '17 at 3:54
5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.