..

nginx 配置 keepalive

今天在配置了 nginx 以后发现无法访问服务,nginx 返回503

2020/08/26 21:08:38 [error] 30814#0: *66294 upstream prematurely closed connection while reading response header from upstream, client:

这看起来是远程服务器关闭了连接,这里就不好理解了,为甚么上游服务端在nginx还在读取数据的时候关闭tcp连接呢。最后在上网找了以下,虽然没有想明白原因,但是配置keepalive 能解决这个问题

server {
    ...

    location /http/ {
        proxy_pass http://http_backend;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        ...
    }
}

参考链接