Nginx 504 Gateway Time-out Error resolution method _nginx

Source: Internet
Author: User
Tags fpm

In general, this situation may be due to the Nginx default fastcgi process response buffer too small, which will cause the fastcgi process to be suspended, if your fastcgi service to this suspend processing is not good, then it is very likely to cause the 504 Gateway Time-out
Now the site, especially some forums have a lot of replies and a lot of content, a page even has hundreds of K
The default fastcgi process response buffer is 8K and we can set the larger point

In nginx.conf, join:

Fastcgi_buffers 8 128k

This means that the fastcgi buffer is set to 8x128k
Of course, if you are doing an immediate operation, you may need to nginx the timeout parameter, for example, set to 60 seconds:

Send_timeout 60;

I just adjusted these two parameters, the result is no longer show that timeout, you can say that the effect is good

Another article

The first is to change several configurations of the PHP-FPM:

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

Change the request_terminate_timeout from the previous 0s to 60s, so that the php-cgi process script timeout is 60 seconds, preventing the process from being suspended and increasing utilization efficiency.

Then change the nginx of several configuration items, reduce the number of FASTCGI requests, as far as possible to maintain buffers unchanged:

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

OK, reload php-fpm and Nginx configuration, again test, so far two weeks time no longer appear 504 Gateway time-out situation, is to achieve the effect.

In addition, the default static processing of PHP-FPM can make the process of php-cgi to occupy memory for a long time and cannot be released, which is also one of the causes of Nginx error, so can change the PHP-FPM processing mode to 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.