502 Bad Gateway after Ghost restart

Posted December 15, 2014 16.1k views

I’ve recently been playing around with Ghost as a possible blogging platform and attempted to install a theme I found. I put the files into the ghost/content/themes folder and extracted the zip (that all went just fine). I then went to restart ghost as is suggested on the guide I was following and I’m now getting a 502 error from nginx.


The only command I tried to restart with was sudo service ghost restart.

I then found and attempted to do the same but to nginx and it said it restarted just fine but I’m still getting a 502 error.

Here is a copy of my /var/log/nginx/error.log -

1 comment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
6 answers

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.


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.

  • Thanks so much @arunprasadr,

    These things are strange as today after a maintenance restart i got the Bad Gateway but your were totally right on the fix, changed the ports from 2368 to 2369 for the proxy upstream in my .conf files, restarted Ghost and Nginx and all is well :)

    Thanks my friend!

  • Thanks a lot, I had the same problem, and the fix worked great.

    I think the breaking part is, once we start up ghost, in the command line it suggested I run an update, which probably ended up with the miss match in the port numbers.


By looking at your error.log it looks like you might have a looping problem and haven’t configure your blog url. Open config.js in your root directory and enter your domain name instead of

I would also restart nginx and ghost after that.

  • Hi aguilar1181, thanks for your answer. But sadly I’ve already done that when I first set everything up. My production url is set to ’’.

    Any other ideas would be much appreciated!

  • I think I might have a solution. Try this to restart ghost

    npm start --production

    People have complaint that using this code to restart it always give them that 502 error and more specifically the complaint was use on another forum and they said it was in a DO server

    sudo service ghost restart
  • @aguilar1181 That’s exactly what the Upstart script should be doing when you run
    sudo service ghost restart

    description "Ghost: Just a blogging platform"
    start on (local-filesystems and net-device-up IFACE=eth0)
    stop on runlevel [!12345]
    # If the process quits unexpectedly trigger a respawn
    setuid ghost
    setgid ghost
    env NODE_ENV=production
    chdir /var/www/ghost
    exec /usr/local/bin/npm start --production
    pre-stop exec /usr/local/bin/npm stop --production

    Though running it directly might show us what’s going on here. I’d also check the contents of /var/log/upstart/ghost.log

I am getting similar error after ghost restart and log file suggest:
verbose stack Error: ENOENT, open ’/var/www/package.json’
this persist after cache clean.


I know it’s an old thread and I apologize for reviving but this thread just helped me get my ghost app back up and running after restoring a failed upgrade attempt. I’d like to point out that you should “cd” to your ghost installation folder before running npm –start production.. like this:

cd /var/www/ghost

This is an example of the ghost installation folder, YMMV.

After CD'ing to it, run the following:

npm start --production