How to install wordpress 502 Bad Gateway in nginx

Source: Internet
Author: User
Tags fpm install wordpress nginx reverse proxy


Wordpress 502 Bad Gateway solution

First, modify the configuration of php-fpm:

// Www/wdlinux/php/etc/php-fpm.conf

/Www/wdlinux/etc/php-fpm.conf change max_children from the previous 10 to the current 30, so that there is sufficient php-cgi process can be used;
Change request_terminate_timeout from the previous 0 s to 60 s, so that the timeout time for the php-cgi process to process the script is 60 seconds, which can prevent the process from being suspended and improve the utilization efficiency.

Open/usr/local/php/etc/php-fpm.conf

Increase the following two parameters (too large based on the actual situation of the server)

5120

600

504 timeout

Send_timeout 60;

Fastcgi_buffers 8 128 k;

In/www/wdlinux/nginx/conf/nginx. conf

To add and adjust the two parameters.


I. fastcgi buffer settings are too small

If an error occurs, first find the nginx log file in the directory/var/log/nginx. The following error is found in the log: www.111cn.net.

13:33:47 [error] 15421 #0: * 16 upstream sent too big header while reading response header from upstream

After checking the information, the problem was caused by a bug in the nginx buffer zone. The page consumption on our website may be too large.

I found a solution on the Internet, and found a method for adding a buffer on a foreign website, which completely solved the problem of Nginx 502 Bad Gateway. The method is as follows:
 
Http {
...
Fastcgi_buffers 8 16 k;
Fastcgi_buffer_size 32 k;
...
}

Increase the preceding two configuration items based on your website.

II. The proxy buffer settings are too small
If you are using nginx reverse proxy, if the header is too large, it exceeds the default 1 k, the above upstream sent too big header will be triggered (to put it bluntly, nginx will process external requests to the backend. If the header returned by the backend is too large, nginx will cause 502 if it cannot process it.


 
Server {
Listen 80;
Server_name *. lxy. me;
Location /{
############## Add the three rows
Proxy_buffer_size 64 k;
Proxy_buffers 32 32 k;
Proxy_busy_buffers_size 128 k;
############## Add the three rows
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.
502 problems occur during installation and use. Generally, the default php-cgi process is five, which may be caused by insufficient phpcgi processes, you need to modify/usr/local/php/etc/php-fpm.conf to add the max_children value as appropriate. It is also possible that the max_requests value is insufficient. It must be noted that this configuration item occupies a large amount of memory. Please set it according to the server configuration. Otherwise, it may have a negative effect.

4. php execution timeout: www.111cn.net
Php execution time-out. Modify/usr/local/php/etc/php. ini and change max_execution_time to 300.

5. nginx wait time timeout
The execution time of some PHP programs exceeds the Nginx waiting time. You can add the FastCGI timeout time in the nginx. conf configuration file as appropriate.


 
Http {
Fastcgi_connect_timeout 300;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300;
......
  }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.