コピペコードで快適生活

明日使えるソースを自分のために

proxy先がTCPコネクションを切ったときブラウザには何が返るか

ブラウザ → proxy(nginx) → origin(apache) の通信経路で、originがTCPコネクションを切った場合、proxyは50xを返す。proxy(nginx)にはこんなログが出る。

proxy_1  | 2021/07/01 13:15:38 [error] 25#25: *2 upstream prematurely closed connection while reading response header from upstream, client: 172.20.0.1, server: localhost, request: "GET /php/ HTTP/1.1", upstream: "http://172.20.0.2:80/", host: "localhost"
proxy_1  | time:01/Jul/2021:13:15:38 +0000  remote_addr:172.20.0.1  host:localhost  scheme:http req:GET /php/ HTTP/1.1  status:502  size:494    response_time:5.655referer:-    agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36 upstream_addr:172.20.0.2:80 upstream_cache_status:- upstream_response_time:5.656

ブラウザで、ERR_CONNECTION_CLOSEDが出る場合は、ブラウザとproxy間の通信が切れたもの。