502 Bad Gateway - Ghost APP and Nginx

December 16, 2014 5.9k views

Hello, I'm getting the 502 bad gateway with my ghost application.
I have researched all over the internet and I found no answers for this.

My Ghost config.js:

var path = require('path'),

config = {
    // ### Production
    // When running Ghost in the wild, use the production environment
    // Configure your URL and mail settings here
    production: {
        url: 'http://supetar.italoborg.es',
        mail: {},
        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(__dirname, '/content/data/ghost.db')
            debug: false

        server: {
            // Host to be passed to node's `net.Server#listen()`
            host: '',
            // Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
            port: '2368'

My Nginx supetar.italoborg.es file:

server {

        server_name supetar.italoborg.es;
        root /home/italo/www/supetar.italoborg.es/html;
        index index.html index.htm index.js;
        access_log /var/log/nginx/supetar.italoborg.es.log;

        location / {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header HOST $http_host;
                proxy_set_header X-NginX-Proxy true;

                proxy_redirect off;

                # Socket.IO Support
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";

I created the symbolic link to folder sites-enabled:

lrwxrwxrwx 1 root root 47 Dec 16 12:10 supetar.italoborg.es -> /etc/nginx/sites-available/supetar.italoborg.es

And I'm using PM2 to start the Ghost APP:

pm2 start index.js

When I try to start the Ghost APP using:

npm start

I can see the blog, but when I try with pm2, I'm getting bad gateway.

Ubunt 14.04 64bits
Node v0.10.13
Npm 2.1.12


2 Answers


It looks like Ghost is failing to start. Can you try starting it manually and posting the output?

node index.js
  • When I try with npm or node, everything works fine:

    Migrations: Up to date at version 003
    Ghost is running... 
    Your blog is now available on http://supetar.italoborg.es 
    Ctrl+C to shut down

Now, maybe, i found the solution, but i don't know why.

I deleted PM2 and installed Forever, guess what, WORKS!

Have another answer? Share your knowledge.