/ Tech Ideas

Ghost Blog 502 Error after upgrading

和功夫-W与出bug的Ghost Blog战了一天

Wasted a whole afternoon on fixing 502 Bad Gateway for Ghost Blog.

Strange as it appears to be, npm start --production worked for me yet service ghost start does not. I did upgrade both node and Ghost Blog today and I was extremely confused by the symptom of this bug (like what the hell is the difference between service and npm start?).

Skip to the conclusion: the problem is caused by upgrading the node. When I upgraded it, I used n (it's like a node version manager which allows you to switch between different versions of node), which changed the directory of the node my OS uses.

If you use service script to keep the blog online:

  1. run which node to find the directory of node, mine gives: /usr/local/bin/node
  2. vim(or nano as you may like) /etc/init.d/ghost
    mine appears to be:
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Ghost"
NAME=ghost
GHOST_ROOT=/var/www/ghost
GHOST_GROUP=ghost
GHOST_USER=ghost
DAEMON=/usr/bin/node
DAEMON_ARGS="$GHOST_ROOT/index.js"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
export NODE_ENV=production

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
  1. Change DAEMON=/usr/bin/node into DAEMON=/usr/local/bin/node and everything will be fine again.