error 504 gateway timeout on nginx

my web app keeps throwing a 504 gateway timeout when querying a large database. how do i increase the timeout limit in nginx?

hey, i had this exact problem last month! you wanna look for `proxy_read_timeout` in your nginx config. put it in the `http`, `server`, or `location` block. usually default is 60s, i bumped mine to like 300s for a really heavy report. also check `proxy_connect_timeout` and `proxy_send_timeout` just to be safe. but honestly, it might also be worth checking why the query is taking so long, timeouts just hide the issue sometimes.
 
my web app keeps throwing a 504 gateway timeout when querying a large database. how do i increase the timeout limit in nginx?

hey, i had this exact problem last month! you wanna look for `proxy_read_timeout` in your nginx config. put it in the `http`, `server`, or `location` block. usually default is 60s, i bumped mine to like 300s for a really heavy report. also check `proxy_connect_timeout` and `proxy_send_timeout` just to be safe. but honestly, it might also be worth checking why the query is taking so long, timeouts just hide the issue sometimes.

oh nice thanks for the tip i'll try that
 
A 504 Gateway Timeout on Nginx usually means your server didn’t get a response in time from the backend (like PHP-FPM, Node app, or upstream server), so it’s more of a backend delay than an Nginx issue. I’ve run into this before when PHP scripts were slow or the server was overloaded—fixes usually involve increasing proxy_read_timeout / fastcgi_read_timeout, checking if your backend service is running properly, and looking at server load or logs (/var/log/nginx/error.log). If it’s happening randomly, it’s often a performance bottleneck rather than a config mistake.
 
Error 504 Gateway Timeout on Nginx occurs when the Nginx server acts as a gateway or proxy and does not receive a timely response from the upstream server (such as an application server, PHP-FPM, or another web server).

This usually happens due to a slow backend server, heavy traffic, server overload, network issues, or incorrect timeout settings. It can be fixed by checking the backend service, increasing Nginx timeout limits, optimizing server performance, or restarting the web server and related services.
 
Back
Top