How to troubleshoot "504 Gateway time-out" error

Source: Internet
Author: User

Do site students often find some Nginx server access when prompted 504 Gateway time-out error, generally by the Nginx default fastcgi process response slow, but there are other situations, here I summed up some solutions for your reference.

Method/Step
  1. Situation one: Due to nginx default fastcgi process response buffer too small caused

    This situation causes the FASTCGI process to be suspended, and if the FASTCGI service is not well-handled, it may prompt "504 Gateway time-out" error.

  2. Situation One solution:

    The default fastcgi process response buffer is 8K, we can set a larger, in nginx.conf, join: Fastcgi_buffers 8 128k

    This indicates that the fastcgi buffer is set to a size of 8 128k in space.

  3. Situation one solution (improvement):

    After the above method is modified, if the problem still occurs, we can continue to modify the Nginx timeout parameter, the parameter is a bit larger, such as set to 60 seconds:

    Send_timeout 60;

    After the adjustment of these two parameters, the results did not prompt "504 Gateway time-out" error, indicating that the effect is quite good, the problem is basically solved.

  4. Scenario Two: Configuration issues for the PHP environment

    Here we need to make configuration changes to PHP-FPM and Nginx. Because of this scenario, the "504 Gateway time-out" error message appears.

  5. Situation two solutions (PHP-FPM configuration Modification):

    Change the Max_children from the previous 10 to 30, so the operation is to ensure that there is sufficient php-cgi process can be used.

    Change the request_terminate_timeout from the previous 0 seconds to 60 seconds, which increases the time-out of the PHP-CGI process processing script to 60 seconds, preventing the process from being suspended to improve utilization efficiency.

  6. Scenario Two solutions (Nginx configuration Modification):

    In order to reduce the number of FASTCGI requests, as far as possible to maintain buffers unchanged, we want to change the Nginx several configuration items, as follows:

    Change the fastcgi_buffers from 4 to 64k to 2 256k;

    Change the fastcgi_buffer_size from 64k to 128k;

    Change the fastcgi_busy_buffers_size from 128k to 256k;

    Change the fastcgi_temp_file_write_size from 128k to 256k.

  7. 7

    When the two solutions are modified, we need to reload the PHP-FPM and Nginx configurations before testing. Then did not find "504 Gateway time-out" error, the effect is also good!

How to troubleshoot "504 Gateway time-out" error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.