The website returns 502 when opened, check the program or the gateway layer first.
Firstly, determine who sent this response: 502 indicates that it is returned by the gateway or proxy layer, meaning that as the forwarding party, it received an invalid response from the upstream. The protocol document defines this status code in this way. That is to say, the request has reached the gateway, and the gateway has also tried to forward it, but the problem lies in the section from the gateway to the application, not the section from the browser to the site. Divide the responsibility into three steps: bypass the gateway and directly connect to the source station, check the gateway error logs, and check the program process and port listening. Do not reverse the order, otherwise you will repeatedly find the cause of another layer within one layer.
Which part fails when 502 is mentioned?
A response can be called 502 under two conditions: there is a gateway or proxy server at this hop, and it received a response from the upstream but considered it invalid. It is not the same as 'program error': the business error code returned by the program itself is a valid response, and the gateway will pass it through unchanged, so the browser sees the status code rather than 502. Therefore, when 502 occurs, it is worth suspecting the interpretation of the upstream response by the forwarding link - connection is disconnected, response is incomplete, protocol does not match, process exits during processing, and they will all present as this kind.
How to differentiate from the errors where the response cannot be obtained
The document specifies that if the proxy or gateway does not receive any HTTP response from the source site, it returns a 504 Gateway Timeout to the client.This distinction can save half of the troubleshooting direction: Getting a 502 means that the upstream has a response but it is invalid, the process is mostly alive; Getting a 504 means that the response cannot be obtained, and you need to check for timeout configurations, process hangs, or port unavailability;When you encounter results like connection reset or rejected connection, which have no HTTP status at all, it's more like a problem with the listening and network layer. Three manifestations correspond to three causes, do not mix the parameters together.
Three-step pot division
Step one, bypass the gateway and connect directly to the source station. By directly making a request once to the listening port on the server, if you can get the normal page, it means there is no problem with the application side, the problem is with the gateway configuration or the connectivity between the gateway and the source station.Direct connection is also abnormal, only then enter the application side for troubleshooting. Second step, check the gateway error logs, pay attention to the records of upstream connection failure, timeout, and protocol errors, aligning the time point with the minute when the fault occurred.Step 3, check the process and port monitoring: Is the process running, is the listening address the one pointed to by the gateway configuration, and is it in the restart cycle? The deployment method within the site (one-click deployment on the panel, command deployment, or container image) defaults to listening on port 8001. The address of the gateway reverse proxy must be consistent with this actual listening port. This kind of inconsistency is one of the common sources of 502 issues.
The impact of deployment form on troubleshooting
| Deployment form | The relationship between gateway and program | Troubleshooting focus | Easy to misjudge places |
|---|---|---|---|
| Panel reverse proxy | Panel configuration forwarding to local port | Forwarding address and certificate configuration | Changed the site but still looking at the old configuration |
| Handwritten gateway configuration | Maintain the upstream address yourself | Upstream address, timeout, protocol version | Increase timeout to cover process crash |
| Container deployment | Port mapping with an extra hop | Mapping and network connectivity | Treat container network issues as program issues |
Pay more attention to container shape: port mapping and network name resolution are between gateway and program, direct connection on host does not mean reachable in container network. For panel deployment, first confirm which forwarding configuration the current site is bound to, and correcting the site is the most common time-consuming source in this type of troubleshooting.
Leave a fallback before taking action
Changing the gateway configuration is an operation that can affect the availability of the entire site. Before making any changes, it is recommended to back up the current gateway configuration file and site data. Test changes one at a time, do not change multiple places at once and then restart the entire system. The site has backup and recovery capabilities, covering the library data and static files, and with the copy of the configuration file, rollback is executable rather than just a principle.
Common questions
Question: If only a certain page returns 502 and others are normal, is it still a gateway issue?Answer: It seems more like this request caused the program to end in the middle. First, check the corresponding function and program logs of the page, as the gateway side generally does not report errors for specific paths separately.
Ask: The program restarts immediately after, do we need to continue to investigate?Answer: Yes. Restarting only restores the scene, the reason for the process exit is still in the log, and if it is not cleared, it will happen again.
Ask: Can increasing the gateway timeout solve the 502 issue?Answer: This belongs to the 504 direction. The cause of 502 is to get an invalid response, and the timeout parameter generally does not change this point.