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

An example of how to quickly deploy web applications using Tomcat in Docker

After learning the basic operations of Docker, we...

How to use cookies to remember passwords for 7 days on the vue login page

Problem Description In the login page of the proj...

Use auto.js to realize the automatic daily check-in function

Use auto.js to automate daily check-in Due to the...

DOCTYPE type detailed introduction

<br />We usually declare DOCTYPE in HTML in ...

Master the commonly used HTML tags for quoting content in web pages

Use blockquote for long citations, q for short ci...

How to implement communication between Docker containers

Scenario: A laradock development environment (php...

MySQL 5.7.21 installation and configuration method graphic tutorial (window)

Install mysql5.7.21 in the window environment. Th...

The difference between Input's size and maxlength attributes

I recently used the input size and maxlength attri...

Detailed explanation of downloading, installing and using nginx server

download http://nginx.org/en/download.html Unzip ...

Summary of MySQL database like statement wildcard fuzzy query

MySQL error: Parameter index out of range (1 >...

Implementation of React page turner (including front and back ends)

Table of contents front end According to the abov...

Web skills: Multiple IE versions coexistence solution IETester

My recommendation Solution for coexistence of mul...

Vue parent component calls child component function implementation

Vue parent component calls the function of the ch...

Detailed explanation of the marquee attribute in HTML

This tag is not part of HTML3.2 and is only suppo...

How to underline the a tag and change the color before and after clicking

Copy code The code is as follows: a:link { font-s...