"502 Bad Gateway nginx/1.4.6 (Ubuntu)" error after upgrrading ghost from 0.7.9 to 0.11.1

Posted March 26, 2017 46.8k views

I just upgrade ghost from 0.7.9 to 0.11.1 by following this guide on After the upgrade which completed without errors I get “502 Bad Gateway nginx/1.4.6 (Ubuntu)” when I try to visit the site. When I revert to my backup everything works fine. And when I say “revert to my backup” I don’t mean restoring the whole server I just mean “cp -R ./ghost-backup ./ghost”. A reboot was not required after reverting back to the backup either. Something is failing with the upgrade but I have no idea what.

My theme is Casper 1.2.8.

This is what appeared in the error log for nginx.

2017/03/26 05:32:23 [error] 1062#0: *21 connect() failed (111: Connection refused) while connecting to upstream, client: [client IP], server:, request: "GET / HTTP/1.1", upstream: "", host: ""

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


The error you’re receiving is telling you that NGINX isn’t able to connect to the Ghost installation that you’re proxying to (i.e. the upstream), so the issue most likely isn’t with NGINX here, rather, Ghost.

Are you receiving any errors or warnings during the Ghost upgrade? What version of NodeJS are you currently running? Last I recall, Ghost only supports 4.x and 6.x, so if you’re running a version other than those two, that may also be the issue.

What I would recommend, temporarily, is stopping NGINX using:

service nginx stop


systemctl stop nginx

Then modifying your config file to use your Droplet’s Public IP and restart Ghost, then try to access it using port 2368. See if that works, or if you receive an error. If you receive an error, we can be 100% sure that it’s Ghost and not NGINX.

I recommend this as NGINX is basically taking a request on port 80 and relaying it to the Ghost port when you’re using proxy_pass. It’ll pass on headers and details of the connection, but beyond that, NGINX terminates the request there and Ghost picks up.

The node version v4.4.3. I think we can rule out node being incompatible with ghost since ghost 0.7.9 works fine and also this is Digital Ocean’s ghost one click install image and I doubt they would select the wrong version of node.

I don’t think there’s any question that the problem is ghost and not nginx since everything works with version 0.7.9 but not 0.11.1 and I’m not changing anything at all with nginx. However, doing what suggest results in a connection timeout:

The connection has timed out

The server at [IP] is taking too long to respond.

    The site could be temporarily unavailable or too busy. Try again in a few moments.
    If you are unable to load any pages, check your computer’s network connection.
    If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.

There were warnings but the ghost upgrade instructions say warnings are not a problem. Here are the warnings:

root@ghost:/var/www/ghost-new# npm install --production
npm WARN cannot run in wd ghost@0.11.7 node core/server/utils/npm/preinstall.js (wd=/var/www/ghost-new)
npm WARN peerDependencies The peer dependency knex@>=0.6.10 <0.13.0 included from bookshelf will no
npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency 
npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.

> jsonpath@0.2.9 postinstall /var/www/ghost-new/node_modules/jsonpath
> node lib/aesprim.js > generated/aesprim-browser.js

> knex@0.12.5 postinstall /var/www/ghost-new/node_modules/knex
> node ./scripts/build.js lib "npm run build"

> sqlite3@3.1.8 install /var/www/ghost-new/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build

[sqlite3] Success: "/var/www/ghost-new/node_modules/sqlite3/lib/binding/node-v46-linux-x64/node_sqlite3.node" is installed via remote
> dtrace-provider@0.6.0 install /var/www/ghost-new/node_modules/gscan/node_modules/ghost-ignition/node_modules/bunyan/node_modules/dtrace-provider
> node scripts/install.js

domelementtype@1.3.0 node_modules/domelementtype

ini@1.3.4 node_modules/ini

normalize-path@2.0.1 node_modules/normalize-path

lodash.defaults@4.2.0 node_modules/lodash.defaults

object-assign@4.1.0 node_modules/object-assign

lodash.merge@4.6.0 node_modules/lodash.merge

inherits@2.0.3 node_modules/inherits

on-headers@1.0.1 node_modules/on-headers

vary@1.1.0 node_modules/vary

passport-oauth2-client-password@0.1.2 node_modules/passport-oauth2-client-password

passport-http-bearer@1.0.1 node_modules/passport-http-bearer

passport-strategy@1.0.0 node_modules/passport-strategy

graceful-fs@4.1.11 node_modules/graceful-fs

connect-slashes@1.3.1 node_modules/connect-slashes

pg-connection-string@0.1.3 node_modules/pg-connection-string

semver@5.3.0 node_modules/semver

xtend@4.0.1 node_modules/xtend

json-stringify-safe@5.0.1 node_modules/json-stringify-safe

rss@1.2.2 node_modules/rss

extend@3.0.0 node_modules/extend

xml@1.0.1 node_modules/xml

depd@1.1.0 node_modules/depd

generic-pool@2.4.2 node_modules/generic-pool

uuid@3.0.0 node_modules/uuid

entities@1.1.1 node_modules/entities

domutils@1.5.1 node_modules/domutils

cors@2.8.1 node_modules/cors

image-size@0.5.1 node_modules/image-size

node-uuid@1.4.7 node_modules/node-uuid

dom-serializer@0.1.0 node_modules/dom-serializer
└── domelementtype@1.1.3

ghost-gql@0.0.6 node_modules/ghost-gql

once@1.3.3 node_modules/once
└── wrappy@1.0.2

on-finished@2.3.0 node_modules/on-finished
└── ee-first@1.1.1

sanitize-html@1.14.1 node_modules/sanitize-html
└── regexp-quote@0.0.0

combined-stream@1.0.5 node_modules/combined-stream
└── delayed-stream@1.0.0

bcryptjs@2.4.3 node_modules/bcryptjs

commander@2.9.0 node_modules/commander
└── graceful-readlink@1.0.1

generate-object-property@1.2.0 node_modules/generate-object-property
└── is-property@1.0.2

iconv-lite@0.4.15 node_modules/iconv-lite

isobject@2.1.0 node_modules/isobject
└── isarray@1.0.0

mime-types@2.1.13 node_modules/mime-types
└── mime-db@1.25.0

passport@0.3.2 node_modules/passport
└── pause@0.0.1

downsize@0.0.8 node_modules/downsize
└── xregexp@2.0.0

nan@2.4.0 node_modules/nan

chalk@1.1.3 node_modules/chalk
├── escape-string-regexp@1.0.5
├── supports-color@2.0.0
├── ansi-styles@2.2.1
├── strip-ansi@3.0.1 (ansi-regex@2.1.1)
└── has-ansi@2.0.0 (ansi-regex@2.1.1)

bluebird@3.4.7 node_modules/bluebird

path-match@1.2.4 node_modules/path-match
├── path-to-regexp@1.7.0 (isarray@0.0.1)
└── http-errors@1.4.0 (inherits@2.0.1, statuses@1.3.1)

moment-timezone@0.5.9 node_modules/moment-timezone

form-data@2.1.2 node_modules/form-data
└── asynckit@0.4.0

morgan@1.7.0 node_modules/morgan
├── basic-auth@1.0.4
└── debug@2.2.0 (ms@0.7.1)

cookie-session@1.2.0 node_modules/cookie-session
├── cookies@0.5.0 (keygrip@1.0.1)
└── debug@2.2.0 (ms@0.7.1)

validator@6.2.1 node_modules/validator

optimist@0.6.1 node_modules/optimist
├── wordwrap@0.0.3
└── minimist@0.0.10

fs-extra@2.0.0 node_modules/fs-extra
└── jsonfile@2.4.0

cheerio@0.22.0 node_modules/cheerio
├── lodash.pick@4.4.0
├── lodash.foreach@4.5.0
├── lodash.flatten@4.4.0
├── lodash.assignin@4.2.0
├── lodash.bind@4.2.1
├── lodash.filter@4.6.0
├── lodash.reduce@4.6.0
├── lodash.reject@4.6.0
├── lodash.some@4.6.0
└── css-select@1.2.0 (boolbase@1.0.0, css-what@2.1.0, nth-check@1.0.1)

glob@5.0.15 node_modules/glob
├── path-is-absolute@1.0.1
├── inflight@1.0.6 (wrappy@1.0.2)
├── once@1.4.0 (wrappy@1.0.2)
└── minimatch@3.0.3 (brace-expansion@1.1.6)

bl@1.2.0 node_modules/bl
└── readable-stream@2.2.3 (buffer-shims@1.0.0, string_decoder@0.10.31, process-nextick-args@1.0.7, util-deprecate@1.0.2, core-util-is@1.0.2, isarray@1.0.0)

compression@1.6.2 node_modules/compression
├── bytes@2.3.0
├── compressible@2.0.9 (mime-db@1.26.0)
├── debug@2.2.0 (ms@0.7.1)
└── accepts@1.3.3 (negotiator@0.6.1, mime-types@2.1.14)

body-parser@1.16.0 node_modules/body-parser
├── content-type@1.0.2
├── bytes@2.4.0
├── qs@6.2.1
├── raw-body@2.2.0 (unpipe@1.0.0)
├── http-errors@1.5.1 (setprototypeof@1.0.2, statuses@1.3.1)
├── debug@2.6.0 (ms@0.7.2)
└── type-is@1.6.14 (media-typer@0.3.0, mime-types@2.1.14)

netjet@1.1.3 node_modules/netjet
├── lodash.unescape@4.0.1
├── lru-cache@4.0.2 (pseudomap@1.0.2, yallist@2.0.0)
├── posthtml@0.9.2 (posthtml-parser@0.2.1, posthtml-render@1.0.6)
└── hijackresponse@2.0.1

oauth2orize@1.7.0 node_modules/oauth2orize
├── uid2@0.0.3
├── utils-merge@1.0.0
└── debug@2.6.1 (ms@0.7.2)

htmlparser2@3.9.2 node_modules/htmlparser2
├── domhandler@2.3.0
└── readable-stream@2.2.3 (buffer-shims@1.0.0, string_decoder@0.10.31, process-nextick-args@1.0.7, util-deprecate@1.0.2, core-util-is@1.0.2, isarray@1.0.0)

express@4.14.1 node_modules/express
├── escape-html@1.0.3
├── array-flatten@1.1.1
├── cookie-signature@1.0.6
├── utils-merge@1.0.0
├── content-type@1.0.2
├── encodeurl@1.0.1
├── methods@1.1.2
├── merge-descriptors@1.0.1
├── path-to-regexp@0.1.7
├── content-disposition@0.5.2
├── cookie@0.3.1
├── etag@1.7.0
├── fresh@0.3.0
├── parseurl@1.3.1
├── range-parser@1.2.0
├── serve-static@1.11.2
├── qs@6.2.0
├── finalhandler@0.5.1 (unpipe@1.0.0, statuses@1.3.1)
├── debug@2.2.0 (ms@0.7.1)
├── proxy-addr@1.1.3 (forwarded@0.1.0, ipaddr.js@1.2.0)
├── type-is@1.6.14 (media-typer@0.3.0, mime-types@2.1.14)
├── send@0.14.2 (ms@0.7.2, destroy@1.0.4, statuses@1.3.1, mime@1.3.4, http-errors@1.5.1)
└── accepts@1.3.3 (negotiator@0.6.1, mime-types@2.1.14)

superagent@3.4.1 node_modules/superagent
├── component-emitter@1.2.1
├── methods@1.1.2
├── cookiejar@2.1.0
├── mime@1.3.4
├── formidable@1.1.1
├── qs@6.3.1
├── debug@2.6.1 (ms@0.7.2)
└── readable-stream@2.2.3 (buffer-shims@1.0.0, string_decoder@0.10.31, process-nextick-args@1.0.7, util-deprecate@1.0.2, core-util-is@1.0.2, isarray@1.0.0)

extract-zip-fork@1.5.1 node_modules/extract-zip-fork
├── debug@0.7.4
├── yauzl@2.4.1 (fd-slicer@1.0.1)
├── mkdirp@0.5.0 (minimist@0.0.8)
└── concat-stream@1.5.0 (typedarray@0.0.6, readable-stream@2.0.6)

pg@6.1.2 node_modules/pg
├── packet-reader@0.2.0
├── pg-pool@1.6.0
├── buffer-writer@1.0.1
├── semver@4.3.2
├── pg-types@1.11.0 (postgres-bytea@1.0.0, postgres-array@1.0.2, postgres-interval@1.0.2, postgres-date@1.0.3, ap@0.2.0)
└── pgpass@1.0.1 (split@1.0.0)

bookshelf@0.10.2 node_modules/bookshelf
├── create-error@0.3.1
└── inflection@1.12.0

csv-parser@1.11.0 node_modules/csv-parser
├── generate-function@1.1.0
├── minimist@1.2.0
└── ndjson@1.5.0 (split2@2.1.1, through2@2.0.3)

showdown-ghost@0.3.6 node_modules/showdown-ghost

unidecode@0.1.8 node_modules/unidecode

amperize@0.3.4 node_modules/amperize
├── emits@3.0.0
└── async@2.1.4

html-to-text@3.1.0 node_modules/html-to-text
├── underscore@1.8.3
├── he@1.1.1
└── underscore.string@3.3.4 (util-deprecate@1.0.2, sprintf-js@1.0.3)

multer@1.3.0 node_modules/multer
├── object-assign@3.0.0
├── append-field@0.1.0
├── type-is@1.6.14 (media-typer@0.3.0, mime-types@2.1.14)
├── mkdirp@0.5.1 (minimist@0.0.8)
├── concat-stream@1.6.0 (typedarray@0.0.6, readable-stream@2.2.3)
└── busboy@0.2.14 (readable-stream@1.1.14, dicer@0.2.5)

archiver@1.3.0 node_modules/archiver
├── buffer-crc32@0.2.13
├── tar-stream@1.5.2 (end-of-stream@1.1.0)
├── walkdir@0.0.11
├── archiver-utils@1.3.0 (lazystream@1.0.0)
├── readable-stream@2.2.3 (buffer-shims@1.0.0, string_decoder@0.10.31, process-nextick-args@1.0.7, util-deprecate@1.0.2, core-util-is@1.0.2, isarray@1.0.0)
├── glob@7.1.1 (path-is-absolute@1.0.1, fs.realpath@1.0.0, inflight@1.0.6, once@1.4.0, minimatch@3.0.3)
├── async@2.1.5
└── zip-stream@1.1.1 (compress-commons@1.1.0)

intl-messageformat@1.3.0 node_modules/intl-messageformat
└── intl-messageformat-parser@1.2.0

moment@2.17.1 node_modules/moment

mysql@2.1.1 node_modules/mysql
├── require-all@0.0.3
├── readable-stream@1.1.14 (string_decoder@0.10.31, isarray@0.0.1, core-util-is@1.0.2)
└── bignumber.js@1.0.1

jsonpath@0.2.9 node_modules/jsonpath
├── underscore@1.7.0
├── esprima@1.2.2
├── static-eval@0.2.3 (escodegen@0.0.28)
└── jison@0.4.13 (jison-lex@0.2.1, lex-parser@0.1.4, cjson@0.2.1, ebnf-parser@0.1.10, esprima@1.0.4, nomnom@1.5.2, escodegen@0.0.21, JSONSelect@0.4.0)

knex@0.12.5 node_modules/knex
├── tildify@1.0.0
├── v8flags@2.0.11
├── interpret@0.6.6
├── user-home@1.1.1
├── minimist@1.1.3
├── debug@2.6.1 (ms@0.7.2)
├── readable-stream@1.1.14 (string_decoder@0.10.31, isarray@0.0.1, core-util-is@1.0.2)
├── mkdirp@0.5.1 (minimist@0.0.8)
└── liftoff@2.2.5 (rechoir@0.6.2, flagged-respawn@0.3.2, resolve@1.3.2, findup-sync@0.4.3)

express-hbs@1.0.4 node_modules/express-hbs
├── readdirp@2.1.0 (set-immediate-shim@1.0.1, readable-stream@2.2.3, minimatch@3.0.3)
├── js-beautify@1.6.8 (nopt@3.0.6, config-chain@1.1.11, mkdirp@0.5.1, editorconfig@0.13.2)
└── handlebars@4.0.6 (async@1.5.2, source-map@0.4.4, uglify-js@2.8.4)

intl@1.2.5 node_modules/intl

lodash@4.17.4 node_modules/lodash

nodemailer@0.7.1 node_modules/nodemailer
├── public-address@0.1.2
├── directmail@0.1.8
├── he@0.3.6
├── readable-stream@1.1.14 (string_decoder@0.10.31, isarray@0.0.1, core-util-is@1.0.2)
├── simplesmtp@0.3.35 (xoauth2@0.1.8, rai@0.1.12)
├── mailcomposer@0.2.12 (mime@1.2.11, dkim-signer@0.1.2, follow-redirects@0.0.3, mimelib@0.2.19)
└── aws-sdk@2.0.5 (xmlbuilder@0.4.2, aws-sdk-apis@3.1.10, xml2js@0.2.6)

sqlite3@3.1.8 node_modules/sqlite3

gscan@0.2.0 node_modules/gscan
├── package-json-validator@0.6.0
├── require-dir@0.1.0
├── chalk@1.1.1 (supports-color@2.0.0, escape-string-regexp@1.0.5, ansi-styles@2.2.1, has-ansi@2.0.0, strip-ansi@3.0.1)
├── bluebird@3.4.6
├── fs-extra@0.26.2 (path-is-absolute@1.0.1, rimraf@2.6.1, jsonfile@2.4.0, klaw@1.3.1)
├── glob@7.0.5 (path-is-absolute@1.0.1, fs.realpath@1.0.0, inflight@1.0.6, once@1.4.0, minimatch@3.0.3)
├── express@4.14.0 (escape-html@1.0.3, array-flatten@1.1.1, utils-merge@1.0.0, cookie-signature@1.0.6, merge-descriptors@1.0.1, methods@1.1.2, encodeurl@1.0.1, content-type@1.0.2, fresh@0.3.0, parseurl@1.3.1, path-to-regexp@0.1.7, content-disposition@0.5.1, range-parser@1.2.0, cookie@0.3.1, etag@1.7.0, qs@6.2.0, debug@2.2.0, finalhandler@0.5.0, proxy-addr@1.1.3, send@0.14.1, accepts@1.3.3, type-is@1.6.14, serve-static@1.11.2)
├── multer@1.1.0 (object-assign@3.0.0, append-field@0.1.0, type-is@1.6.14, mkdirp@0.5.1, concat-stream@1.6.0, busboy@0.2.14)
├── lodash@3.10.1
├── express-hbs@1.0.3 (readdirp@2.1.0, js-beautify@1.6.4, handlebars@4.0.6)
└── ghost-ignition@1.0.0 (caller@1.0.1, find-root@1.0.0, debug@2.2.0, prettyjson@1.1.3, nconf@0.8.4, bunyan@1.8.1, moment@2.15.2, lodash@4.16.4)

babel-runtime@6.23.0 node_modules/babel-runtime
├── regenerator-runtime@0.10.3
└── core-js@2.4.1

  • @setec

    From what I can see, everything looks good with the output and those warnings are just that, so no need to be concerned with those right off.

    Is Ghost generating any sort of error log that would shed some light on the situation? If not, can you try and run:

    npm start --production >> /var/log/ghost.log

    It could be something with Ghost, or it could be theme related in the event the theme relies on something that changed between versions. Having an actual log that’ll detail what’s going on should make things a little easier to pinpoint.

It seems that the problem was the theme. Before doing the log test you suggested I finally upgraded the theme. I hesitated because the documentation made it sound optional and I wasn’t sure if I’d modified the theme or not.

So I think we can conclude that Casper 1.2.8 does not work on Ghost 0.11.1. The documentation could be clearer, they make it sound like upgrading the theme is optional.

  • @setec

    A theme issue was at the top of my potentials given my past experience with WordPress and some of the themes authors fail to maintain or just give up on – especially since you weren’t having any other noticeable issues when running the install.

    Glad to hear you were able to figure it out!

I reported it to the support team and they said that some of the documentation may be out of date. They are planning to review and update after the release of ghost v1.0.