Nginx的上游服务器关闭连接时如何关闭客户端连接?

时间:2018-11-02 12:05:21

标签: nginx tcp

(1)我有一个http服务器,侦听端口8080,在处理GET请求时睡眠5秒:

class myHandler(BaseHTTPRequestHandler):
def do_GET(self):
    self.send_response(200)
    self.send_header('Content-type','text/html')
    self.end_headers()
    self.wfile.write("Hello World !")
    time.sleep(5)
    print 'after sleep'
    return
try:
    server = HTTPServer(('', 8080), myHandler)
    server.serve_forever()
except KeyboardInterrupt:
    server.socket.close()

(2)我有一个nginx,监听1014并将请求转发到8080,

upstream kubeapiserver {
    server 127.0.0.1:8080;
    keepalive 30;
}
server {
    listen       1014;
    server_name  127.0.0.1;
    location / {
        proxy_pass http://kubeapiserver;
        proxy_http_version 1.1;
        proxy_connect_timeout 1800s;
        proxy_read_timeout 1800s;
        proxy_send_timeout 1800s;
    }
}

(3)向1014发出长时间请求

import time
url="http://127.0.0.1:1014"
s = requests.Session()
r = s.get(url)
print r.headers
print r.status_code
print r.content
while True:
    time.sleep(10)

我发现netstat -nap | egrep "(8080)|(1014)"发现: 当B连接关闭时,A连接仍然建立

当Nginx的上游服务器关闭连接时,如何关闭客户端连接?如何配置?

0 个答案:

没有答案