Proxying request - HTTP/1.1 502 Bad Gateway
Maxim Dounin
mdounin at mdounin.ru
Tue Aug 9 09:00:39 UTC 2011
Hello!
On Tue, Aug 09, 2011 at 02:12:19AM -0400, michalkraus wrote:
> Hello,
> we have problem with proxying some RPC (POST) requests to a backend
> server.
> When a request is sent without proxy to the backend directly everrything
> is OK. So problem is probably caused by nginx proxy.
> When the request is sent from the same server as proxy is installed,
> response is allways OK as well.
> The problem occurs just when a method with many parameters is called
> (large POST request). And the strangest thing is that the same request
> is sometimes OK and sometimes produces 502 Bad Gateway.
>
> A part of http section from nginx.conf:
> client_header_buffer_size 32k;
> large_client_header_buffers 4 64k;
> client_body_buffer_size 32k;
> proxy_buffer_size 32k;
> proxy_buffers 8 16k;
> proxy_busy_buffers_size 64k;
> sendfile on;
> #tcp_nopush on;
> tcp_nodelay on;
> keepalive_timeout 5;
> keepalive_requests 50;
> server_tokens off
>
> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
>
> and the location just:
> location ~ "^/public/RPC2$" {
Just a side note: it's better to use
location = /public/RPC2 {
instead.
> proxy_pass http://localhost:3352;
> }
>
> Part of debug log, when the request is not processed correctly:
[...]
> 2011/08/08 16:05:25 [debug] 23971#0: *218 recv: fd:48 0 of 32768
> 2011/08/08 16:05:25 [error] 23971#0: *218 upstream prematurely closed
> connection while reading response header from upstream, client:
> 10.0.132.6, server: xxxxxxxxxxxx, request: "POST /public/RPC2 HTTP/1.1",
> upstream: "http://127.0.0.1:3352/public/RPC2", host: "yyyyyyyyyyyyyy"
Backend closed connection here. You may want to inspect backend
logs (or debug your backend) to find out why it did that.
While it certainly possible that backend doesn't like something in
nginx request (compared to direct one), it's not possible to say
what exactly without debugging backend.
Maxim Dounin
More information about the nginx
mailing list