Nginx proxy_pass未传递Expect:100-continue头,如何转发全部请求?
Got it, let's tackle this issue head-on. By default, Nginx handles the Expect:100-continue header internally—it sends a 100 Continue response directly to the client, then forwards the request body to the backend without passing the original Expect header. To ensure all inbound requests (including this header) are fully forwarded to your proxy server, you'll need to adjust two key Nginx directives in your location block.
Here's the step-by-step configuration:
Required Configuration
Add these lines inside the location block where you've set up proxy_pass:
location /your-target-endpoint/ { proxy_pass http://your-backend-service; # 1. Explicitly pass the Expect header from client to backend proxy_set_header Expect $http_expect; # 2. Tell Nginx not to handle the Expect header internally proxy_ignore_headers Expect; # Optional: Ensure all other request headers are forwarded (default is on, but explicit is safe) proxy_pass_request_headers on; }
What Each Directive Does:
proxy_set_header Expect $http_expect;: This copies the exact value of the client'sExpectheader into the request sent to the backend. Without this, Nginx strips the header before forwarding.proxy_ignore_headers Expect;: Disables Nginx's default behavior of interceptingExpect:100-continuerequests. Instead, the full request (including the header) is sent to the backend, letting the backend decide whether to respond with100 Continueor handle the request directly.proxy_pass_request_headers on;: Ensures all other client request headers are forwarded to the backend. This is enabled by default, but declaring it explicitly prevents issues if you've modified this setting elsewhere in your config.
Testing the Fix
To verify the header is being forwarded, use curl to send a test request:
curl -v -H "Expect: 100-continue" -X POST -d "sample-data" http://your-nginx-domain/your-target-endpoint/
Check your backend server's access logs—you should see the Expect:100-continue header present in the incoming request.
内容的提问来源于stack exchange,提问作者Left Over

