How to fix 504 gateway timeout error in aws use ELB
  1. Home
  2. English Blog
  3. How to fix 504 gateway timeout error in aws use ELB
Admin 5 tháng trước

How to fix 504 gateway timeout error in aws use ELB

The problem

I have an application PHP + Laravel in AWS with Elastic Beanstalk and Elastic Load Balancer. I have implemented some time-consuming features such as importing CSV files with many records and exporting large datasets. However, the system returns a 504 Gateway Timeout error during these operations. Even though I have increased the timeouts in Nginx and PHP, I still encounter this issue.

How to fix

1. Increase connection idle timeout Elastic Load Balancer

By default, AWS Elastic Load Balancing sets the idle timeout value for your load balancer to 60 seconds. How to change ?

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
  2. On the navigation pane, choose Load Balancers.
  3. Select the load balancer.
  4. On the Attributes tab, choose Edit.
  5. Under Traffic configuration, enter a value for Connection idle timeout. The valid range is 1 through 4000 seconds.
  6. Choose Save changes.

Reference: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/application-load-balancers.html

2. Increase Nginx Timeout Settings

Nginx Configuration:

http {
 ...
 proxy_connect_timeout 60s;
 proxy_send_timeout 60s;
 proxy_read_timeout 60s;
 send_timeout 60s;
 ...
}

Reload the Nginx configuration to apply changes:
sudo systemctl reload nginx

3. Increase PHP Timeout Settings

You need to increase the max_execution_time value in PHP using the following methods:

  1. Using the ini_set function:
    ini_set('max_execution_time', '300');
  2. Setting the max_execution_time value in the php.ini file:
; Maximum execution time of each script, in seconds
; https://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 300

27 lượt xem | 0 bình luận
Tác giả vẫn chưa cập nhật trạng thái
Đề xuất cho bạn

Avatar