Nginx 504 Gateway Time-out error solution

Source: Internet
Author: User
Tags fpm

In general, this situation may be caused by the small buffer of nginx's default fastcgi Process response, which will cause the fastcgi process to be suspended. If your fastcgi service does not handle this suspension well, in the end, 504 Gateway Time-out may occur.
Today's websites, especially some forums, have a lot of replies and a lot of content. One page even has hundreds of K
The default fastcgi Process response buffer is 8 kB. We can set a large value.

In nginx. conf, add:

Fastcgi_buffers 8 128 k

This indicates that the fastcgi buffer is set to 8*128 k.
Of course, if you are performing an immediate operation, you may need to increase the value of the nginx timeout parameter, for example, to 60 seconds:

Send_timeout 60;

I just adjusted the two parameters, and the result is that the timeout value is not displayed. It can be said that the effect is good.

Another article

First, modify the configuration of php-fpm:

Change max_children from the previous 10 to the current 30, so that sufficient php-cgi processes can be used;

Change request_terminate_timeout from the previous 0 s to 60 s, so that the timeout time for the php-cgi process to process the script is 60 seconds, which can prevent the process from being suspended and improve the utilization efficiency.

Then, modify several nginx configuration items to reduce the number of FastCGI requests and try to keep buffers unchanged:

Change fastcgi_buffers from 4 64 k to 2 256 k;
Fastcgi_buffer_size is changed from 64 k to 128 K;
Fastcgi_busy_buffers_size is changed from 128 K to 256 K;
Fastcgi_temp_file_write_size is changed from 128 K to 256 K.

Okay, reload the configuration of php-fpm and nginx, and test again. So far, No 504 Gateway Time-out has been found in two weeks.

In addition, the default static processing method of php-fpm will make the php-cgi process occupy the memory for a long time and cannot be released, which is also one of the causes of nginx errors, therefore, you can change the php-fpm processing method to the apache mode.
Apache-like

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.