Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the nginx "504 Gateway Time-out" error

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to solve nginx" 504 Gateway Time-out "errors". In daily operation, I believe many people have doubts about how to solve nginx "504 Gateway Time-out" errors. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to solve nginx" 504 Gateway Time-out errors! Next, please follow the editor to study!

Method / step scenario 1: because the default fastcgi process response buffer of nginx is too small

In this case, the fastcgi process is suspended, and if the hang handling of the fastcgi service team is not very good, it may prompt a "504 Gateway Time-out" error.

Situation one solution:

The default buffer for fastcgi process response is 8K. We can set it a little larger. In nginx.conf, add: fastcgi_buffers 8 128k

This means that the fastcgi buffer is set to 8 blocks of 128k.

Situation one solution (improvement):

After the above method is modified, if there is still a problem, we can continue to modify the timeout parameter of nginx, and adjust the parameter a little larger, such as setting it to 60 seconds:

Send_timeout 60

After the adjustment of these two parameters, the result does not prompt "504 Gateway Time-out" error, indicating that the effect is quite good, and the problem is basically solved.

Case 2: configuration of PHP environment

Here we need to make configuration changes to php-fpm and nginx. Because in this case, there will also be a "504 Gateway Time-out" error.

Case 2 solution (php-fpm configuration modification):

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

Change the request_terminate_timeout from 0 seconds to 60 seconds, which increases the timeout time for the php-cgi process to process scripts to 60 seconds, preventing the process from being suspended and improving utilization efficiency.

Case 2 solution (nginx configuration modification):

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

Change fastcgi_buffers from 4 64k to 2 256k

Change fastcgi_buffer_size from 64k to 128k

Change fastcgi_busy_buffers_size from 128k to 256k

Change fastcgi_temp_file_write_size from 128k to 256k.

In case 2, after the solution has been modified, we need to reload the configuration of php-fpm and nginx before testing. After that, no "504 Gateway Time-out" error was found, and the effect was good!

At this point, the study on "how to solve the nginx" 504 Gateway Time-out "error" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report