502Bad Gateway Error after restarting Ghost

And

  • How was Ghost installed and configured? I followed the guide to install on Ubuntu.
  • What Node version, database, OS & browser are you using? Node v18.18.2, MySql Version 8.0.35-0ubuntu0.22.04.1 for Linux on x86_64, Opera GX Browser.
  • What errors or information do you see in the console? No errors in console. Stopping and starting ghost produces no errors.
    This is what shows when I run the ghost stop and ghost start commands:
blogsoft@blog:/var/www/vertyblog$ ghost stop

Love open source? We’re hiring JavaScript Engineers to work on Ghost full-time.
https://careers.ghost.org


+ sudo systemctl is-active ghost_blog-verty-gay
+ sudo systemctl stop ghost_blog-verty-gay
✔ Stopping Ghost: blog-verty-gay
blogsoft@blog:/var/www/vertyblog$ ghost start

Love open source? We’re hiring JavaScript Engineers to work on Ghost full-time.
https://careers.ghost.org


+ sudo systemctl is-active ghost_blog-verty-gay
✔ Checking system Node.js version - found v18.18.2
✔ Ensuring user is not logged in as ghost user
✔ Checking if logged in user is directory owner
✔ Checking current folder permissions
+ sudo systemctl is-active ghost_blog-verty-gay
✔ Validating config
✔ Checking folder permissions
✔ Checking file permissions
✔ Checking content folder ownership
✔ Checking memory availability
✔ Checking binary dependencies
✔ Checking systemd unit file
✔ Checking systemd node version - found v18.18.2
+ sudo systemctl start ghost_blog-verty-gay
+ sudo systemctl is-enabled ghost_blog-verty-gay
✔ Starting Ghost: blog-verty-gay

------------------------------------------------------------------------------

Your admin interface is located at:

    https://blog.verty.gay/ghost/

  • What steps could someone else take to reproduce the issue you’re having?
    I initially was trying to restart Ghost so my updated config file would take effect. I first got this error:
root@blog:/var/www/vertyblog# su blogsoft
blogsoft@blog:/var/www/vertyblog$ ghost restart

Love open source? We’re hiring JavaScript Engineers to work on Ghost full-time.
https://careers.ghost.org


Ghost instance is not running! Starting...
✖ Starting Ghost
A SystemError occurred.

Message: The content folder is not owned by the current user.
Ensure the content folder has correct permissions and try again.

Debug Information:
    OS: Ubuntu, v22.04.3 LTS
    Node Version: v18.18.2
    Ghost Version: 5.74.2
    Ghost-CLI Version: 1.25.3
    Environment: production
    Command: 'ghost restart'

Try running ghost doctor to check your system for known issues.

You can always refer to https://ghost.org/docs/ghost-cli/ for troubleshooting.

I solved that error by doing this:

blogsoft@blog:/var/www/vertyblog$ sudo chmod 775 /var/www/vertyblog
blogsoft@blog:/var/www/vertyblog$ sudo chown -R blogsoft:blogsoft /var/www/vertyblog

So then I tried doing ghost restart again but got this error:

blogsoft@blog:/var/www/vertyblog$ ghost restart

Love open source? We’re hiring JavaScript Engineers to work on Ghost full-time.
https://careers.ghost.org


+ sudo systemctl is-active ghost_blog-verty-gay
✖ 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.

Debug Information:
    OS: Ubuntu, v22.04.3 LTS
    Node Version: v18.18.2
    Ghost Version: 5.74.2
    Ghost-CLI Version: 1.25.3
    Environment: production
    Command: 'ghost restart'

Try running ghost doctor to check your system for known issues.

You can always refer to https://ghost.org/docs/ghost-cli/ for troubleshooting.
blogsoft@blog:/var/www/vertyblog$ ghost setup linux-user systemd

Love open source? We’re hiring JavaScript Engineers to work on Ghost full-time.
https://careers.ghost.org



Systemd service has already been set up. Skipping Systemd setup
ℹ Setting up Systemd [skipped]
blogsoft@blog:/var/www/vertyblog$ ghost restart

Love open source? We’re hiring JavaScript Engineers to work on Ghost full-time.
https://careers.ghost.org


+ sudo systemctl is-active ghost_blog-verty-gay
✖ 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.

Debug Information:
    OS: Ubuntu, v22.04.3 LTS
    Node Version: v18.18.2
    Ghost Version: 5.74.2
    Ghost-CLI Version: 1.25.3
    Environment: production
    Command: 'ghost restart'

Try running ghost doctor to check your system for known issues.

You can always refer to https://ghost.org/docs/ghost-cli/ for troubleshooting.

I then tried running ghost setup according to this post and got this output:

blogsoft@blog:/var/www/vertyblog$ ghost setup

Love open source? We’re hiring JavaScript Engineers to work on Ghost full-time.
https://careers.ghost.org



? Enter your blog URL: https://blog.verty.gay
? Enter your MySQL hostname: 127.0.0.1
? Enter your MySQL username: ghost-807
? Enter your MySQL password (skip to keep current password): [hidden]
? Enter your Ghost database name: vertyblog_prod
✔ Configuring Ghost
+ sudo chown -R ghost:ghost /var/www/vertyblog/content
✔ Setting up "ghost" system user
ℹ Setting up "ghost" mysql user [skipped]
Nginx configuration already found for this url. Skipping Nginx setup.
ℹ Setting up Nginx [skipped]
Nginx setup task was skipped, skipping SSL setup
ℹ Setting up SSL [skipped]
Systemd service has already been set up. Skipping Systemd setup
ℹ Setting up Systemd [skipped]
+ sudo systemctl is-active ghost_blog-verty-gay
ℹ Starting Ghost [skipped]

Ghost uses direct mail by default. To set up an alternative email method read our docs at https://ghost.org/docs/config/#mail

------------------------------------------------------------------------------

Ghost was installed successfully! To complete setup of your publication, visit:

    https://blog.verty.gay/ghost/

And now Ghost seems to stop and start fine, according to the command line output, but I get a 502 error when trying to access my blog or my admin dashboard at https://blog.verty.gay/

1 Like

Ok, I managed to fix this on my own after some more Googling. It turns out that the port that Ghost was using got increased by one (2368 → 2369). So I just had to update the ports in the files in /etc/nginx/sites-enabled and now it works fine!

Credit to this old Stackoverflow thread that helped me figure it out: nginx - What is the cause of the "502 Bad Gateway" after Ghost 1.8.7 update - Stack Overflow

2 Likes