You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nginx proxy_pass未传递Expect:100-continue头,如何转发全部请求?

Fixing Nginx Not Forwarding Expect:100-continue Headers to Backend

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's Expect header 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 intercepting Expect:100-continue requests. Instead, the full request (including the header) is sent to the backend, letting the backend decide whether to respond with 100 Continue or 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:46:59