I have an admin app running on the AWS VM, which is connected to another VM called Openvpn server. We have some servers in my office that are connected to the AWS open VPN virtual machine. I used the Nginx reverse proxy to connect the local server to the main server. When some users open the Admin App and upload videos to the panel, they are uploaded to the office’s local server via an OpenVPN connection. My issue was that when the user uploaded large videos, I received a 504 gateway timeout error.
Initial Attempts:
Upon encountering the 504 gateway timeout error, the first course of action was to increase Nginx’s reverse proxy upload size and timeout settings. While this approach improved file upload handling, it did not fully resolve the issue. The root cause was not just large files but also the time taken for certain uploads, exceeding the default timeout thresholds. You can also use this setting in Nginx as the first step.
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
client_max_body_size 1G; # Adjust the size as needed
client_body_buffer_size 1M;
The final Solution
After thorough investigation, the crucial breakthrough came when realizing the timeout settings on the AWS load balancer. By default, the Connection Idle Timeout setting in the AWS load balancer was configured for 1 minute. This default timeout was insufficient for handling uploads that took longer durations, resulting in the 504 error. The definitive fix involved updating the Connection Idle Timeout setting in the AWS load balancer to a more suitable duration, such as 5 minutes, aligning with the actual upload times.
Go to the AWS load balancer page > Click on Attributes > Update Connection idle timeout
Update the idle timeout to your specifications and upload the large file. You will now be able to upload the files using the above settings.
Conclusion
Dealing with gateway timeout errors during large file uploads requires a comprehensive approach. It’s not just about adjusting Nginx settings but also considering the timeout configurations at the infrastructure level, such as AWS load balancers. By understanding and optimizing these timeout settings, developers can ensure smoother handling of large file uploads without encountering disruptive gateway timeout errors. This real-world scenario underscores the importance of holistic troubleshooting and configuration management in maintaining reliable web services.