DO Ghost droplet 502 Bad Gateway error

Hello!

Today I tried to access my website, and it’s returning a 502 Bad Gateway - nginx/1.18.0 (Ubuntu).

I have Ghost installed in a DigitalOcean 1-click droplet. The url of the web is:

https://escritsensecasa.com/
Ghost version: 5.76.2
node version: 18.17.1

This had happened before, and restarting the droplet would fix it, but this time it didn’t.

I ran an apt-get update and upgrade in case it was an issue with an outdated package, but it’s still not working.

When I run ghost status, it returns the following (it seems to be fine):

│ Name │ Location │ Version │ Status │ URL │ Port │ Process Manager │
├─────────────────────┼────────────────┼─────────┼──────────────────────┼─────────────────────────────┼──────┼─────────────────┤
│ escritsensecasa-com │ /var/www/ghost │ 5.76.2 │ running (production) │ https://escritsensecasa.com │ 2368 │ systemd

The ghost doctor returns the following:

:heavy_check_mark: Checking system Node.js version - found v18.17.1
:heavy_check_mark: Checking logged in user
:heavy_check_mark: Ensuring user is not logged in as ghost user
:heavy_check_mark: Checking if logged in user is directory owner
:heavy_check_mark: Checking current folder permissions
:heavy_check_mark: Checking system compatibility
:heavy_check_mark: Checking for a MySQL installation

  • sudo systemctl is-active ghost_escritsensecasa-com
    Instance is currently running
    :information_source: Validating config [skipped]
    :heavy_check_mark: Checking folder permissions
    :heavy_check_mark: Checking file permissions
    :heavy_check_mark: Checking memory availability
    :heavy_check_mark: Checking binary dependencies
    :heavy_check_mark: Checking free space
    :heavy_check_mark: Checking systemd unit file
    :heavy_check_mark: Checking systemd node version - found v18.17.1

On the other hand, the MySQL status also appears to be correct:

sudo systemctl status mysql.service
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2024-09-07 09:44:11 UTC; 27min ago
Process: 6584 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 6592 (mysqld)
Status: “Server is operational”
Tasks: 38 (limit: 1101)
Memory: 64.9M
CPU: 11.176s
CGroup: /system.slice/mysql.service
└─6592 /usr/sbin/mysqld

Sep 07 09:44:09 escritsensecasa systemd[1]: mysql.service: Deactivated successfully.
Sep 07 09:44:09 escritsensecasa systemd[1]: Stopped MySQL Community Server.
Sep 07 09:44:09 escritsensecasa systemd[1]: mysql.service: Consumed 3.640s CPU time.
Sep 07 09:44:09 escritsensecasa systemd[1]: Starting MySQL Community Server…
Sep 07 09:44:11 escritsensecasa systemd[1]: Started MySQL Community Server.

I’m running out of ideas and I can’t make it work. Any idea where the problem is?

Thanks in advance!!

Have you checked the Nginx status?

this error says that nginx is not getting the expected response from ghost - to try and narrow it down, you could try restarting Ghost and checking the logs for clues

#  from the ghost directory e.g /var/www/ghost 
ghost restart
ghost log 
# error log
ghost log -e

nginx logs:

sudo systemctl status nginx
sudo journalctl -u nginx.service

Hi! Thank you for the reply!

It’s weird, when trying to restart (with ghost-mgr user), I get the following message:

+ sudo systemctl is-active ghost_escritsensecasa-com
✖ Restarting Ghost
A SystemError occurred.

Message: Systemd process manager has not been set up or is corrupted.
Help: Run ghost setup linux-user systemd and try again.

If I run ghost setup linux-user systemd i get the message saying it’s already configured and skip it:

Systemd service has already been set up. Skipping Systemd setup

But when running ghost doctor, says that user permissions are right.

When running ghost log, it shows that there’s an error when connecting with the database:

[2024-09-07 09:26:26] ERROR

NAME: DatabaseError
CODE: ER_ACCESS_DENIED_ERROR
MESSAGE: Access denied for user 'paula'@'localhost' (using password: YES)

level: critical

"Unknown database error"
Error: Access denied for user 'paula'@'localhost' (using password: YES)
    at /var/www/ghost/versions/5.76.2/node_modules/knex-migrator/lib/database.js:57:19
    at Packet.asError (/var/www/ghost/versions/5.76.2/node_modules/mysql2/lib/packets/packet.js:728:17)
    at ClientHandshake.execute (/var/www/ghost/versions/5.76.2/node_modules/mysql2/lib/commands/command.js:29:26)
    at Connection.handlePacket (/var/www/ghost/versions/5.76.2/node_modules/mysql2/lib/connection.js:478:34)
    at PacketParser.onPacket (/var/www/ghost/versions/5.76.2/node_modules/mysql2/lib/connection.js:97:12)
    at PacketParser.executeStart (/var/www/ghost/versions/5.76.2/node_modules/mysql2/lib/packet_parser.js:75:16)
    at Socket.<anonymous> (/var/www/ghost/versions/5.76.2/node_modules/mysql2/lib/connection.js:104:25)
    at Socket.emit (node:events:514:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)

On the other hand, nginx status seems fine, and the logs too:

● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2024-09-07 13:26:37 UTC; 19h ago
       Docs: man:nginx(8)
    Process: 722 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCC>
    Process: 799 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 817 (nginx)
      Tasks: 2 (limit: 1101)
     Memory: 3.8M
        CPU: 1.248s
     CGroup: /system.slice/nginx.service
             ├─817 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             └─825 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >

Sep 07 13:26:36 escritsensecasa systemd[1]: Starting A high performance web server and a reverse proxy server...
Sep 07 13:26:37 escritsensecasa systemd[1]: Started A high performance web server and a reverse proxy server.

Logs:

-- Boot 9f24ca929ef24a65855a452d27e6014f --
Sep 07 09:38:06 escritsensecasa systemd[1]: Starting A high performance web server and a reverse proxy server...
Sep 07 09:38:07 escritsensecasa systemd[1]: Started A high performance web server and a reverse proxy server.
Sep 07 13:26:06 escritsensecasa systemd[1]: Stopping A high performance web server and a reverse proxy server...
Sep 07 13:26:07 escritsensecasa systemd[1]: nginx.service: Deactivated successfully.
Sep 07 13:26:07 escritsensecasa systemd[1]: Stopped A high performance web server and a reverse proxy server.

I checked the congi file from Ghost and mysql credentials are the ones that I always been using.

Thank you so much!

it looks like there is something wrong with the mysql database configuration and this is preventing the ghost service from starting.

You will get the ER_ACCESS_DENIED_ERROR error if the user, password or database values specified in config.production.json are incorrect.

Thank you Nick. No idea, because i didn’t touch ghost config file. But i did reinstall mysql yesterday to see if that solved the issue.

If not, do you know if there’s a way to make a backup from terminal of what I have in the web? I know that in content I can recover the photos, but I was wondering theme, text, images, like a proper backup.

Thank you!

It is difficult to advise you without knowing what steps you did to reinstall mysql, but if you just updated the binaries then hopefully your data and user accounts have been preserved.

you can back up the data like this:

mysqldump -u root -p --all-databases > mysql.sql

…probably worth doing this this as a precaution before making any other changes.

if the ghost database and user is still present, then it might simply be a case of updating the database user’s (‘paula’@‘localhost’, in your case) password to reflect whatever is in your config file.

if you have lost the database content, I’m afraid you will have lost your post content and will need some form of backup, e.g a Ghost json export to recover your site.