8

I recently installed Ghost 1.8.4 and Nginx on my AWS ec2 Ubuntu 16.04 server. When I loaded my blog site, it correctly took me to the Ghost home page, from where I logged into Ghost admin. On the admin screen, there was a message to update.

I ran ghost update in putty

The update appeared to be successful, but when I returned to my blog site, I received the following error:

502 Bad Gateway nginx/1.10.3 (Ubuntu)

  1. Does anyone know a probably cause of this error and how to resolve?
  2. I checked some posts, which suggested I should have turned Ghost off before the update. If this is true, is my ghost installation now corrupted?
  3. I went to my ghost directory in /var/www/ghost and tried to run:

    sudo service ghost start

    but it returned:

    Failed to start ghost.service: Unit ghost.service not found

    and trying to stop, returns Unit ghost.service not loaded. Am I running the command from the correct location?

Wronski
  • 1,506
  • 3
  • 18
  • 37
  • any output for `which ghost`? – Tarun Lalwani Sep 21 '17 at 19:11
  • @TarunLalwani, Ghost CMS https://ghost.org/ installed via CLI – Wronski Sep 22 '17 at 00:35
  • No, I mean executing the command from terminal `which ghost` and `ghost start` what does that give you? – Tarun Lalwani Sep 22 '17 at 04:13
  • @TarunLalwani, `which ghost` returns `/usr/bin/ghost` and when i go to `var/www/ghost` and run `ghost start` i get: `✖ Starting Ghost An error occurred. Message: 'EACCES: permission denied, open '/var/www/ghost/.ghost-cli'' Debug Information: Node Version: v6.11.3 Ghost-CLI Version: 1.1.1 Environment: production Command: 'ghost start' Additional log info available in: /home/ubuntu/.ghost/logs/ghost-cli-debug-2017-09-23T04_00_01_360Z.log Please refer to https://docs.ghost.org/docs/v1/troubleshooting#section-cli-errors for troubleshooting.` – Wronski Sep 23 '17 at 03:59
  • Did you try `sudo ghost start` – Tarun Lalwani Sep 23 '17 at 05:38
  • I did try that @TarunLalwani. It seems that somehow the error has resolved itself. Unfortunately I don't know how. Thank you for the help. – Wronski Sep 24 '17 at 01:12

3 Answers3

15

I've experienced 502 issues with ghost behind nginx several times over a few years of running it. I'm not sure if the cause of mine today is the same as yours, but what I observed was that after a restart ghost had changed its port number to one different than what its nginx config was listening on.

I followed these directions from https://web.archive.org/web/20200807095031/https://www.danwalker.com/running-ghost-on-a-5-digital-ocean-vps/ which resolved it for me:

See which port ghost is running on:

sudo netstat -plotn

Check that it matches the proxy_pass in the nginx config file in /etc/nginx/sites-enabled.

In my case the port in the nginx config had incremented to 2369 while the actual node process was running on 2368. Changing the proxy_pass port back to 2368 in my ghost blog's nginx config file resolved the issue for me.

tagurit
  • 494
  • 5
  • 13
Taylor D. Edmiston
  • 12,088
  • 6
  • 56
  • 76
  • 7
    This is what solved the problem for me after upgrading to Ghost 2.6.0. The Nginx config had port 2368 while Ghost was running on 2369. – clpo13 Nov 14 '18 at 19:03
  • Same here, after upgrading to Ghost 2.18.1. Same pair of ports, even (2368, but now 2369). – David Mar 16 '19 at 01:43
7

I ran into the same problem after upgrading ghost.

Make sure the port number configured in your ghost's config file and the proxy_pass in your ghost site's nginx configuration files match.

Check the port number in /var/www/ghost/config.production.json matches the proxy_pass port in the nginx config files.

/var/www/ghost/system/files/<yourDomainName>.<extension>.conf
/var/www/ghost/system/files/<yourDomainName>.<extension>-ssl.conf

In my case I had to change 2368 to 2369 in the nginx config files to fix the issue.

Make sure you restart your ghost and nginx after you make the changes.

# restart your ghost site
cd /var/www/ghost/
ghost restart 
# restart nginx
sudo systemctl restart nginx

Hope this helps someone.

Arun Prasad
  • 291
  • 5
  • 9
1

Apparently when I posted this issue it was due to a bug in the Ghost CLI that the ghost team were in the process of fixing.

They provided me with these instructions to run on my server:

systemctl stop ghost_www-blogwebsite-com
ghost update --force

The resulting output:

stopping Ghost [skipped]
Removing old Ghost versions [skipped]

This fixed the problem and updated to the correct version.

Wronski
  • 1,506
  • 3
  • 18
  • 37