nginx – passing request headers to upstream server as body

This example does two things:

1) Changes a GET request from the client to a POST
2) Captures the request headers from the client and converts them to a body for POST to the upstream server

Note we have underscores in our request headers, so we have to enable underscores in our http directive. We then read each request header variable, and concatenate them to the body for submission.

events {}

http {
  underscores_in_headers on;
  upstream esb  {
    server upstreamserver.domain:8889;
  }

  server {
    location /api {
        proxy_pass http://esb/api;
        proxy_method POST;
        proxy_set_body "$http_po_id$http_vendor_id$http_quantity$http_price_per";
    }
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.