I have encountered the Nginx 502 Bad Gateway error several times. I’ll make a note of it here as a reminder. There are many situations in which 502 errors may occur. Let's talk about each situation separately. 1. The fastcgi buffer is set too small When an error occurs, first look for the nginx log file in the directory /var/log/nginx. The following error is found in the log. 2013/01/17 13:33:47 [error] 15421#0: *16 upstream sent too big header while reading response header from upstream After checking the information, I found that there is a bug in the nginx buffer, and the pages on our website may consume too much buffer. I searched for a solution online and saw a method to increase the buffer on a foreign website, which completely solved the Nginx 502 Bad Gateway problem. Here’s how: http { ... fastcgi_buffers 8 16k; fastcgi_buffer_size 32k; ... } Please increase the above two configuration items according to the situation of the server and website. 2. The proxy buffer is set too small If you are using nginx reverse proxy, if the header is too large, exceeding the default 1k, it will trigger the upstream sent too big header mentioned above (to put it simply, nginx sends the external request to the backend for processing, and the header returned by the backend is too large, which nginx cannot process, resulting in 502. server { listen 80; server_name *.lxy.me; location / { ################Add these 3 lines proxy_buffer_size 64k; proxy_buffers 32 32k; proxy_busy_buffers_size 128k; ###############Add these 3 lines proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; ............ } 3. The default number of php-cgi processes is too small If a 502 error occurs during installation and use, it is usually because the default number of php-cgi processes is 5. 502 may be caused by insufficient phpcgi processes. You need to modify /usr/local/php/etc/php-fpm.conf and increase the max_children value appropriately. It is also possible that the max_requests value is not enough. It should be noted that these two configuration items take up a lot of memory, please set them according to the server configuration. Otherwise it may have the opposite effect. 4. PHP execution timeout PHP execution timeout, modify /usr/local/php/etc/php.ini and change max_execution_time to 300 5. nginx waiting time timeout The execution time of some PHP programs exceeds the waiting time of Nginx. You can appropriately increase the timeout time of FastCGI in the nginx.conf configuration file. http { fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; ..... } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: JavaScript single thread and asynchronous details
>>: The use of anchor points in HTML_PowerNode Java Academy
How to solve the problem of being unable to acces...
Q: I don’t know what is the difference between xml...
Table of contents 1. A simplest server-side examp...
This article introduces the command statements fo...
Today, when I searched for a page on Baidu, becaus...
The installation of mysql-5.7.17 is introduced be...
Disadvantages of single-node database Large-scale...
To deploy war with Docker, you must use a contain...
Today I will share with you a good-looking counte...
This article records the installation and configu...
After the container is started Log in to admin fi...
1. What is HTML HTML (HyperText Markup Language):...
Table of contents 1. Template 2. Generics 3. Gene...
In this article, we will look at how to develop a...
Environment Preparation Docker environment MySQL ...