It’s a few days I’m banging my head on this specific problem.
I’ve got a server that performs an operation that takes more that 60 seconds to complete, everything works ok if I connect directly to the server but if I use nginx (v 1.22.1) after 60 seconds I’m disconnected and the server’s answer doesn’t reach the client.
I’ve recreated the situation with this simple python script:
import time
from http.server import BaseHTTPRequestHandler, HTTPServer
class MyHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
time.sleep(66)
self.wfile.write(b'Hello, world!')
if __name__ == '__main__':
server_address = ('', 3000)
httpd = HTTPServer(server_address, MyHandler)
print('Server listening on port 3000...')
httpd.serve_forever()
This is the nginx configuration that tries to increment wait time but without success:
server {
listen 80;
server_name xxx.my.domain;
location / {
proxy_pass http://192.168.4.150:3000;
proxy_connect_timeout 120s;
proxy_send_timeout 120s;
proxy_read_timeout 120s;
send_timeout 120s;
}
}
Now if I connect through the browser, postman or curl the request is truncated after 60s.
Postman says: Could not get response – Error: socket hang up
CURL says:
* Empty reply from server
* Closing connection 0
curl: (52) Empty reply from server
Chrome says: "ERR_EMPTY_RESPONSE"
Of course if I decrease the wait time in the python script to 50s it works.
I’ve tried other settings to avoid cache, keep alive but nothing hasn’t worked so far.
I’m open to new suggestions… 😉
Thank you
Stefano
2
Answers
My bad...
I've found out the problem.
On my mac run a Surfshark VPN that, at least I guess, truncate the answer after 60s.
When I stopped the VPN everything worked as expected.