Nginx prompts 502, 504 error solution collection

Source: Internet
Author: User
Tags fpm

Cause analysis:

To solve these two problems is actually need to think about, in general, Nginx 502 Bad Gateway and php-fpm.conf settings,
Nginx 504 Gateway Time-out is related to nginx. conf settings.
The php-fpm.conf has two crucial parameters: "max_children" and "request_terminate_timeout", but this value is not generic and needs to be calculated on its own.

Method 1: temporary solution:


To sum up, the temporary solutions for Nginx prompting 502 and 504 errors are as follows:

1. Adjust the settings of the php-fpm.conf:

The code is as follows: Copy code

<Value name = "max_children"> 32 </value>
<Value name = "request_terminate_timeout"> 30 s </value>

2. Adjust the nginx. conf settings:

The code is as follows: Copy code

Fastcgi_connect_timeout 600;
Fastcgi_send_timeout 600;
Fastcgi_read_timeout 600;
Fastcgi_buffer_size 256 k;
Fastcgi_buffers' 16 256 k;
Fastcgi_busy_buffers_size 512 k;
Fastcgi_temp_file_write_size 512 k;

Method 2: regularly restart php-fpm:


The solution shown in Heading 3 can only temporarily solve the problem, and if the website traffic is indeed very large, nginx + FastCGI can only achieve good results in handling high concurrency in an instant or a short period of time. Therefore, the only ultimate solution currently is to regularly and smoothly restart php-cgi.

The specific configuration is as follows:

1. Write a very simple script:

The code is as follows: Copy code
# Vi/home/www.scripts/php-fpm.sh
The content is as follows:
#! /Bin/bash
# This script run at */1
/Usr/local/php/sbin/php-fpm reload

2. Add the script to the scheduled task:

The code is as follows: Copy code
# Crontab-e
The content is as follows:
*/1 ***/home/www/scripts/php-fpm.sh

Note: For the sake of convenience, you can directly write the php-fpm smooth restart command in crontab without writing a script.

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.