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

MySQL 8.0.20 compressed version installation tutorial with pictures and text

1. MySQL download address; http://ftp.ntu.edu.tw/...

Configure Mysql master-slave service implementation example

Configure Mysql master-slave service implementati...

Vue globally introduces scss (mixin)

Table of contents 1. mixin.scss 2. Single file us...

Summary of solutions for MySQL not supporting group by

I downloaded and installed the latest version of ...

How to build gitlab on centos6

Preface The original project was placed on the pu...

HTML form component example code

HTML forms are used to collect different types of...

Axios secondary encapsulation example Demo in the project

1. Why do packaging? Facilitates overall code cal...

How to delete extra kernels in Ubuntu

Step 1: View the current kernel rew $ uname -a Li...

Example of implementing text wrapping in html (mixed text and images in html)

1. Text around the image If we use the normal one...

5 ways to migrate Docker containers to other servers

Migration is unavoidable in many cases. Hardware ...

What does the "a" in rgba mean? CSS RGBA Color Guide

RGBA is a CSS color that can set color value and ...

js to implement the snake game with comments

This article example shares the specific code of ...

10 Tips for Mobile App User Interface Design

Tip 1: Stay focused The best mobile apps focus on...