JSOPanel Get started
Help Center › Administrators › A website shows a 502 Bad Gateway error

A website shows a 502 Bad Gateway error

A 502 usually means the account ran out of memory or processes. How to confirm it and fix it.

A 502 Bad Gateway means the web server is running fine, but the PHP program behind the site is not answering. On this server every account runs its own PHP program inside its own memory and process limits, so the most common reason is that the account reached one of those limits. When a PHP program goes over its memory limit, the system stops it (an out-of-memory kill, written as oom-kill in the log). It is started again automatically, but after several quick restarts in a row the system gives up, and the site keeps showing 502 until someone starts it again.

Steps

  1. Open Users & Resellers, click Manage next to the account, and open the Limits tab to see its current Memory and Process limit. The Resource usage page shows how much memory the account is using right now; it reads idle while the account's PHP program is not running.
  2. On the server, read the log of that account's PHP program. Replace 8.3 with the PHP version the site uses and ACCOUNT with the account's username:
    sudo journalctl -u jsop-php8.3-ACCOUNT --since "1 hour ago"
    A memory problem looks like this:
    jsop-php8.3-ACCOUNT.service: Failed with result 'oom-kill'.
    jsop-php8.3-ACCOUNT.service: Consumed 2.401s CPU time, 137.1M memory peak.
    jsop-php8.3-ACCOUNT.service: Scheduled restart job, restart counter is at 34.
    jsop-php8.3-ACCOUNT.service: Start request repeated too quickly.
    jsop-php8.3-ACCOUNT.service: Failed with result 'oom-kill'.
    The memory peak line is a good guide: the account's memory limit has to be comfortably above it.
  3. If you see oom-kill, raise the account's memory. Under Manage → Limits, choose a larger Memory figure, make sure Apply CPU and memory limits when saving is ticked, and click Save all changes. If the account is simply on too small a package, move it to a larger one on the Plan tab instead.
  4. Start the account's PHP program again. This clears the "repeated too quickly" state; each command should print nothing, and the last one should print active:
    sudo systemctl reset-failed jsop-php8.3-ACCOUNT.service
    sudo systemctl restart jsop-php8.3-ACCOUNT.service
    sudo systemctl is-active jsop-php8.3-ACCOUNT.service
  5. Reload the website to confirm it answers.
Tip: raising the limit gets the site back, but find out what needed the memory. A single plugin, a large import, an image-processing job or a runaway script is a common cause. If the site returns to 502 soon after a restart, the cause is still running.

If the log shows a process problem instead

Messages such as Resource temporarily unavailable or can't spawn mean the account reached its Process limit rather than its memory. Each PHP site needs a few processes just to start, so a very low process limit on an account with several sites can leave them all on 502. Raise the process limit on the same Limits tab. On the same tab, PHP workers set to Start when needed keeps fewer PHP processes running while the sites are quiet.

If neither appears in the log

A 502 can also come from the application itself crashing or from the PHP version not suiting it. Check the Error log and the domain's PHP tab as described in A website shows a server error or blank page. How limits work and what each one does is covered in Setting resource limits.