502 Bad Gateway - Ghost APP and Nginx

  • Posted December 16, 2014

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: '',
        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 file:

server {

        root /home/italo/www/;
        index index.html index.htm index.js;
        access_log /var/log/nginx/;

        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 -> /etc/nginx/sites-available/

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



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.


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

node index.js

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

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