Resolving Ghost Blog Connectivity Issues when updating to Node.js v18

Resolving Ghost Blog Connectivity Issues when updating to Node.js v18
Photo by NEOM / Unsplash


Running a Ghost blog on a server, like DigitalOcean, offers great flexibility and control. However, it can sometimes present challenges, especially when it comes to configurations and connectivity. In this post, I'll share my experience of resolving a 502 Bad Gateway error and database connection issues following a Node.js update on my Ghost blog.

The Initial Problem: 502 Bad Gateway

After updating Node.js on my server, I was greeted with a 502 Bad Gateway error when accessing my Ghost blog. This error typically points to issues where the web server (like Nginx) is unable to communicate with the backend service (in this case, Ghost).

Troubleshooting Steps:

  1. Checking Service Status: Ensuring both Nginx and Ghost were running.

    sudo systemctl status nginx
    sudo systemctl status ghost_<your-instance>
  2. Examining Logs: The journalctl and Ghost logs were crucial in revealing that the error was related to a database connectivity issue.

    journalctl -u nginx -n 50
    journalctl -u ghost_<your-instance> -n 50
  3. Ghost and Node.js Compatibility: Verifying the Ghost version was compatible with the updated Node.js version.

Delving Deeper: Database Connection Issues

The logs indicated a connection issue with the error connect ECONNREFUSED ::1:3306. This pointed towards a problem with Ghost connecting to the MySQL database.

Resolving the Database Connectivity Issue:

  1. MySQL Status: Checking and confirming that the MySQL server was active and running.

    sudo systemctl status mysql
  2. Configuration Alignment: The core problem was the mismatch in IP versions between Ghost (expecting IPv6) and MySQL (configured for IPv4).

  3. Editing MySQL Configuration: Aligning the MySQL bind-address in mysqld.cnf.

    sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
    # Change bind-address to ::1
  4. Restarting Services: After the configuration change, both MySQL and Ghost services were restarted.

    sudo systemctl restart mysql
    sudo systemctl restart ghost_<your-instance>