502 Bad gateway How to solve

Source: Internet
Author: User
Tags fpm browser cache

You can try to clear the browser cache access to your FTP to see if you can log in

Cause

A server (not necessarily a Web server) is a gateway or proxy to meet customer requirements, such as a Web browser or our Checkupdown robot, to access the requested URL. This server received an invalid response from an upstream server to fulfill its requirements.

Fixed 502 Error

Generally this problem is due to poor IP communication between the backend computers, including the websites you may try to access on the Web server. In analyzing this problem, you should clear the browser cache completely.

If you look at this problem on all the sites you try to access on the Internet, there are two possibilities

1 Your ISP has a major equipment failure/overload or

2 There is a problem with the internal Internet connection such as your firewall does not function properly.

In the first case, only your ISP can help you. In the second case, what you need to solve is to stop you from getting into the Internet.

If you only have this problem in a part of the Web site you're trying to access, it's probably a problem--one of those sites that has a device failure or overload. Contact the administrator of the Web site.

About 502 Bad Getway the solution to the error of the popular explanation

1. What is 502 bad Getway error

In short, 502 is an error type code bad Getway wrong gateway

2. Causes of Errors

Connection Timeout We send a request to the server because the server is currently linked too much, causing the server to not give the normal response, resulting in such an error

3. Means of salvation

The best solution, of course, is to do it on the server, which is unlikely for everyone.

So what can we do to save it?

Frankly, it's simple.

IS--refresh (not a general refresh OH)

The principle of refreshing: Many people may not know that there are two types of refreshes.

The so-called refresh is actually downloading data from the server to the local hard disk browser,

Then read the data from the local hard disk to the browser to show us.

① Basic Refresh: Click Refresh or use F5 shortcut keys

Basic refresh simply picks up the data from the local hard disk to the browser and does not request the server again.

Most users are often so refreshed, encountered 502 of the error will have no effect.

② from the server refresh: If you re-click on the page you want to browse the link, you will find that the page is still showing 502 bad Getway now can be normal browsing!

Do you understand? When you click on the page you want to browse the link, it will be downloaded from the server data.

The workaround is to refresh from the server: shortcut key Ctrl+f5, which is to resend the request to the server.

If the server can give you a normal response you can see the page.

When using Nginx as a Web server, you are more or less likely to encounter errors in Nginx 502 bad Gateway, causing many of these errors.

Here we come to one by one parsing.

First, see if the php-cgi is running

Sometimes because the site traffic is too large or other reasons, resulting in php-cgi directly down, so we have to see if php-cgi is running. Execute the following command:

ps-a | grep php5-cgi

If it is not running, start manually

/etc/init.d/php_cgi start

If you find php-cgi unexplained and sometimes down, you can use the following script to temporarily resolve this problem and add it to cronjob.

If PS aux | grep ' php5-cgi ' | Grep-v grep >/dev/null; Then echo "php-cgi is runnning!" Else echo "php-cgi are down. Starting over ... "/etc/init.d/php-fcgi start Fi II, the number of fastcgi processes, PHP execution time for a long reason

The number of fastcgi processes can modify the value of the Max_children in php-fpm.conf, the maximum memory consumed at peak time is 20M, calculated according to your memory.

Restricting PHP execution time can be set in the php-fpm.conf request_terminate_timeout to prevent a bug in the PHP program from causing php-cgi to feign death.

Third, fastcgi execution time is too long

Increase the following parameter values according to the actual situation

Fastcgi_connect_timeout 300; Fastcgi_send_timeout 300; Fastcgi_read_timeout 300;

In addition to the three cases listed above, there are certainly other reasons, but above three are the most common

In recent days found that the network of network traffic instability of the server, the specific performance is that the flow is sometimes high, sometimes low, when the flow of low time to find the system's load is very small, almost 0, but after a while, load and high, traffic also went up, is very strange, looking for 2 days did not find the reason, then see side of the article, This paper introduces the problem of solving the error of 502 in Nginx, and tries it according to this method, and finally finds the cause of it.

The resolution steps are as follows:

1. See if the current PHP fastcgi process count is sufficient

Netstat-anpo | grep "php-cgi" | Wc-l

If the actual number of "fastcgi processes" is close to the preset "fastcgi process", then the "fastcgi process count" is not sufficient and needs to be increased.

2, some of the PHP program execution time than the Nginx wait time, you can appropriately increase the nginx.conf configuration file fastcgi timeout time, such as:

In doing the first step, the system is currently the number of PHP fastcgi process is significantly higher than the default value of 64, the number of servers on the telecommunications server to view the current PHP fastcgi no more than 64 of this value, and the network link is significantly more active connections than telecommunications, Ready to look at the time of the evening, the results of the night 22:30, to view the system the current number of PHP fastcgi process is significantly less than 64 preset, the current active connection is much lower than the original, which can be explained that the nginx instability is due to the server access load caused by too much, Just add a second step of the error also does not top the role.

Summary, php-cgi process number is not enough, PHP execution time is long, or php-cgi process dies, there will be 502 errors.

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.