Solve nginx "504 Gateway Time-out" error

Solve nginx "504 Gateway Time-out" error

Students who make websites often find that some nginx servers prompt 504 Gateway Time-out errors when accessing. Generally, this is caused by the slow response of the default fastcgi process of nginx, but there are other situations. Here I summarize some solutions for your reference.

How to resolve the "504 Gateway Time-out" error

Methods/Steps

Case 1: The default fastcgi process response buffer of nginx is too small

This situation causes the fastcgi process to be suspended. If the fastcgi service team does not handle this suspension well, it may prompt a "504 Gateway Time-out" error.

Solution for situation 1:

The default fastcgi process response buffer is 8K, we can set it larger, in nginx.conf , add: fastcgi_buffers 8 128k

This means setting the fastcgi buffer to 8 blocks of 128k in size.

Solution to situation 1 (improvement):

After modifying the above method, if the problem still occurs, we can continue to modify the nginx timeout parameter and increase the parameter a little, such as setting it to 60 seconds:

send_timeout 60;

After adjusting these two parameters, the "504 Gateway Time-out" error was no longer prompted, which shows that the effect is quite good and the problem is basically solved.

Case 2: PHP environment configuration problem

Here we need to modify the configuration of php-fpm and nginx. Because in this case, the "504 Gateway Time-out" error message will also appear.

Solution for situation 2 (php-fpm configuration modification):

Change max_children from 10 30 to ensure that there are enough php-cgi processes available.

Change request_terminate_timeout from 0秒to 60秒. This will increase the timeout period for the php-cgi process to process the script to 60 seconds, which can prevent the process from being hung and improve utilization efficiency.

Solution for situation 2 (modification of nginx configuration):

In order to reduce the number of fastcgi requests and keep buffers unchanged, we need to change several nginx configuration items as follows:

Change fastcgi_buffers from 4 64k to 2 256k ;

Change fastcgi_buffer_size from 64k 128k ;

Change fastcgi_busy_buffers_size from 128k 256k ;

Change fastcgi_temp_file_write_size from 128k 256k .

After the solution to situation 2 is modified, we need to reload the configuration of php-fpm and nginx, and then test it. After that, no "504 Gateway Time-out" errors were found, and the effect is still good!

The above is the editor’s introduction to solving the nginx "504 Gateway Time-out" error. I hope it will be helpful to everyone. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • How to solve the nginx 504 Gateway Time-out error
  • An nginx 504 Gateway Time-out error troubleshooting and solution record
  • Nginx 502 bad gateway and Nginx 504 Gateway Time-out error solutions

<<:  7 interesting ways to achieve hidden elements in CSS

>>:  Several ways to clear arrays in Vue (summary)

Recommend

Detailed explanation of querying JSON format fields in MySQL

During the work development process, a requiremen...

Element Timeline implementation

Table of contents Components - Timeline Custom no...

Using MySQL database with Python 3.4 under Windows 7

The detailed process of using MySQL database with...

MySQL 5.7.18 zip version installation tutorial

The mysql 5.7.18 zip version of MySQL is not like...

Detailed steps to change the default password when installing MySQL in Ubuntu

Step 1: Enter the directory: cd /etc/mysql, view ...

Comparative Analysis of IN and Exists in MySQL Statements

Background Recently, when writing SQL statements,...

JavaScript adds prototype method implementation for built-in objects

The order in which objects call methods: If the m...

RGBA alpha transparency conversion calculation table

Conversion between rgba and filter values ​​under...

Vue two-choice tab bar switching new approach

Problem Description When we are working on a proj...

How to use pdf.js to preview pdf files in Vue

When we preview PDF on the page, some files canno...

How to quickly build an LNMP environment with Docker (latest)

Preface Tip: Here you can add the approximate con...

Detailed explanation of the use of Vue's new built-in components

Table of contents 1. Teleport 1.1 Introduction to...

Detailed explanation of js closure and garbage collection mechanism examples

Table of contents Preface text 1. Closure 1.1 Wha...