Fix 504 Gateway Timeout error using Nginx as reverse Proxy.

When using Nginx as a reverse proxy for Apache, among others, you may get timeouts with error code 504 if an application takes longer to complete a request than the default Nginx request timeout which is 60 seconds. To increase the request timeout in Nginx to serve long-running requests, we need to change the default settings.

This tutorial requires you to be logged in as root, so switch to root user if you are not already.

$ sudo -i

Create a new file timeout.conf in the “/etc/nginx/conf.d/” directory.

# vi /etc/nginx/conf.d/timeout.conf

Add the following code:

proxy_connect_timeout       600;
proxy_send_timeout          600;
proxy_read_timeout          600;
send_timeout                600;

Here we have increased the timeout to 600 seconds, but you can change it to suit your needs.

For the new settings to take effect a restart of Nginx is required.

# systemctl restart nginx

Similar Posts

  • | |

    Generate SSL certificates with acme.sh on Nginx.

    In this article, we will see how to install and configure “acme.sh” to generate SSL certificates for domains and how to implement it with Nginx to secure the connection to corresponding websites hosted on our web server via “HTTPS”. To optimize the security of connections to the web server and comply with all applicable guidelines,…

  • | | | |

    How to install a LEMP stack on Ubuntu 22.04.

    If you’re looking to host your own open source applications, setting up a LEMP (Linux, Nginx, MySQL/MariaDB, PHP) web stack is one of the best choices out there, if not the best. With the latest versions of Nginx, MariaDB, and PHP 8.2, you’ll have a fast and reliable platform for running a wide range of…

  • Enable Keepalive in Nginx Reverse Proxy

    In the Nginx Reverse Proxy context, keepalive connections are a critical performance optimization technique that allows multiple HTTP requests to be transmitted over a single TCP connection, dramatically reducing connection overhead and improving overall system performance. The Performance Challenge Traditional HTTP connections require a complete handshake for each request: This process introduces significant latency and…

  • | |

    WordPress Behind Nginx Reverse Proxy with SSL Termination

    Whenever you run a WordPress website behind a reverse proxy with SSL termination, you encounter a fundamental configuration challenge: the reverse proxy handles HTTPS connections from clients but forwards plain HTTP traffic to the WordPress backend. This creates a mismatch where WordPress, configured with HTTPS URLs (e.g., https://yourdomain.com), receives HTTP requests and becomes confused about…

  • Nginx: [warn] protocol options redefined

    If you get an error message “nginx: [warn] protocol options redefined” after upgrading Nginx to the latest stable version 1.24, you can easily fix it by adding “http2” to the 443 “Listen” directive in the default.conf file. vi /etc/nginx/conf.d/default.conf server { listen 80 default_server; listen [::]:80 default_server; listen 443 default_server http2 ssl; listen [::]:443 default_server…