Nginx reverse proxy returns "504 Timeout while reading response from server"

4/2/2019

I have set up Nginx as a reverse proxy. I am pointing the proxy to a java application. The issue is Nginx returns 504 Timeout while reading response from server after 60 seconds. There is no error log in Nginx or java application. If I hit the java application directly, it serves the request for more than 60 seconds but if I do it via Nginx, it gets timed-out after 60 seconds. I have added the following configs in my nginx.conf file.

proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;
keepalive_timeout 650;

The strange thing is if I change the timeout settings to less than 60 seconds, it works as expected. I have also tried pointing Nginx to a NodeJs application to make sure that the issue is not in java application. The behavior remains the same.

Are there any other configurations I need to fix?

Nginx version: 1.14.0

PS: I also tried this using kubernetes Nginx ingress. The issue remains the same.

-- Nitesh
kubernetes
nginx
proxy
reverse-proxy

0 Answers