Question

Upgraded Ghost to 0.9: 502 Bad Gateway

I’ve just upgraded Ghost using the official guide.

Now when I try to reach my blog it says: 502 Bad Gateway.

In the error log, it says:

2016/08/07 07:32:43 [error] 953#0: *22 connect() failed (111: Connection refused) while connecting to upstream, client: ***, server: my-ghost-blog.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:2368/favicon.ico", host: ***SERVER IP ADDRESS***, referrer: ***SERVER IP ADDRESS***

I checked the config.js file and URL is set to my correct IP address and not to my-ghost-blog.com as per default.

Possibly relevant: when I followed the last step and executed npm install --production I got a bunch of warnings back:

npm WARN cannot run in wd ghost@0.9.0 node core/server/utils/npm/preinstall.js (wd=/var/www/ghost)
npm WARN unmet dependency /var/www/ghost/node_modules/bookshelf requires bluebird@'^2.9.4' but will load
npm WARN unmet dependency /var/www/ghost/node_modules/bluebird,
npm WARN unmet dependency which is version 3.4.1
npm WARN unmet dependency /var/www/ghost/node_modules/ghost-gql requires lodash@'3.10.1' but will load
npm WARN unmet dependency /var/www/ghost/node_modules/lodash,
npm WARN unmet dependency which is version 4.13.1
npm WARN unmet dependency /var/www/ghost/node_modules/jsonpath requires underscore@'1.7.0' but will load
npm WARN unmet dependency /var/www/ghost/node_modules/underscore,
npm WARN unmet dependency which is version 1.8.3
npm WARN unmet dependency /var/www/ghost/node_modules/knex requires bluebird@'^2.9.24' but will load
npm WARN unmet dependency /var/www/ghost/node_modules/bluebird,
npm WARN unmet dependency which is version 3.4.1
npm WARN unmet dependency /var/www/ghost/node_modules/knex requires lodash@'^3.7.0' but will load
npm WARN unmet dependency /var/www/ghost/node_modules/lodash,
npm WARN unmet dependency which is version 4.13.1
npm WARN unmet dependency /var/www/ghost/node_modules/multer requires busboy@'^0.2.11' but will load
npm WARN unmet dependency /var/www/ghost/node_modules/busboy,
npm WARN unmet dependency which is version 0.2.9
npm WARN unmet dependency /var/www/ghost/node_modules/netjet requires lru-cache@'^4.0.0' but will load
npm WARN unmet dependency /var/www/ghost/node_modules/lru-cache,
npm WARN unmet dependency which is version 2.7.0
npm WARN unmet dependency /var/www/ghost/node_modules/pg requires semver@'^4.1.0' but will load
npm WARN unmet dependency /var/www/ghost/node_modules/semver,
npm WARN unmet dependency which is version 5.3.0
npm WARN unmet dependency /var/www/ghost/node_modules/mocha requires escape-string-regexp@'1.0.2' but will load
npm WARN unmet dependency /var/www/ghost/node_modules/escape-string-regexp,
npm WARN unmet dependency which is version 1.0.5
npm WARN unmet dependency /var/www/ghost/node_modules/istanbul/node_modules/js-yaml/node_modules/argparse requires lodash@'>= 3.2.0 < 4.0.0' but will load
npm WARN unmet dependency /var/www/ghost/node_modules/lodash,
npm WARN unmet dependency which is version 4.13.1

Subscribe
Share

Same problem here.


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

So, I ran into this and figured it out. Assuming you’ve followed DigitalOcean’s guide to upgrading Ghost, do the following in your root Ghost folder

npm cache clean
rm -rf node_modules
npm install --production

Now, if all went well you can type

npm start --production

and your blog will start up. The problem here is that it only runs while the console is open. As soon as you hit ctl-c or close the console, your blog will shut down. You need to set up Ghost to run forever. This seems to have been a part of previous installs, but I guess it’s not anymore. You can use Forever, Supervisor, or Init.d to do this. Instructions are here : http://docs.ghost.org/pl/installation/deploy/

In case that link dies, to make Init.d work again, go to /etc/init.d. Create a file called ghost and copy the following into it.

#! /bin/sh
### BEGIN INIT INFO
# Provides:          ghost
# Required-Start:    $network $syslog
# Required-Stop:     $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Ghost Blogging Platform
# Description:       Ghost: Just a blogging platform
### END INIT INFO

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
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/opt/ghost/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
export NODE_ENV=production

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# I like to know what is going on
VERBOSE = yes

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
    # Set up folder structure
    mkdir -p /var/opt/ghost
    mkdir -p /var/opt/ghost/run
    chown -R ghost:ghost /var/opt/ghost
    # Return
    #   0 if daemon has been started
    #   1 if daemon was already running
    #   2 if daemon could not be started
    start-stop-daemon --start --quiet \
        --chuid $GHOST_USER:$GHOST_GROUP --chdir $GHOST_ROOT --background \
        --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
        || return 1
    start-stop-daemon --start --quiet \
        --chuid $GHOST_USER:$GHOST_GROUP --chdir $GHOST_ROOT --background \
        --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS \
        || return 2
    # Add code here, if necessary, that waits for the process to be ready
    # to handle requests from services started subsequently which depend
    # on this one.  As a last resort, sleep for some time.
}

#
# Function that stops the daemon/service
#
do_stop()
{
    # Return
    #   0 if daemon has been stopped
    #   1 if daemon was already stopped
    #   2 if daemon could not be stopped
    #   other if a failure occurred
    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
        --pidfile $PIDFILE --name $NAME
    RETVAL="$?"
    [ "$RETVAL" = 2 ] && return 2
    # Wait for children to finish too if this is a daemon that forks
    # and if the daemon is only ever run from this initscript.
    # If the above conditions are not satisfied then add some other code
    # that waits for the process to drop all resources that could be
    # needed by services started subsequently.  A last resort is to
    # sleep for some time.
    start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 \
        --exec $DAEMON
    [ "$?" = 2 ] && return 2
    # Many daemons don't delete their pidfiles when they exit.
    rm -f $PIDFILE
    return "$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
    #
    # If the daemon can reload its configuration without
    # restarting (for example, when it is sent a SIGHUP),
    # then implement that here.
    #
    start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE \
        --name $NAME
    return 0
}

case "$1" in
start)
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
        do_start
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
stop)
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
        do_stop
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
status)
    status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
    ;;
#reload|force-reload)
        #
        # If do_reload() is not implemented then leave this commented out
        # and leave 'force-reload' as an alias for 'restart'.
        #
        #log_daemon_msg "Reloading $DESC" "$NAME"
        #do_reload
        #log_end_msg $?
        #;;
restart|force-reload)
        #
        # If the "reload" option is implemented then remove the
        # 'force-reload' alias
        #
        log_daemon_msg "Restarting $DESC" "$NAME"
        do_stop
        case "$?" in
        0|1)
                do_start
                do_start
                case "$?" in
                        0) log_end_msg 0 ;;
                        1) log_end_msg 1 ;; # Old process is still running
                        *) log_end_msg 1 ;; # Failed to start
                esac
                ;;
        *)
                # Failed to stop
                log_end_msg 1
                ;;
        esac
        ;;
*)
        #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
        echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
        exit 3
        ;;
esac

:

Save the document. Now run the following commands

update-rc.d ghost defaults 
update-rc.d ghost enable

Now when you type

service ghost start

your blog should run normally.

Hope this helps.

The script on this page made it really easy for me and even fixed what I had messed up trying to do it manually. https://www.ghostforbeginners.com/how-to-update-ghost/

@scottrolsen That worked!! Thank you so much!!!

This comment has been deleted

hola amigos yo hice un tutorial donde ustedes pueden ver paso a paso como solucionar este problema pueden entrar a este blog que está también creado en ghost Tutorial

This comment has been deleted