1

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;

config = {
    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: '127.0.0.1',
            // 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 {
    listen 0.0.0.0:80;

    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_pass http://127.0.0.1:2368;
            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.

I'm using:

Ubunt 14.04 64bits

Node v0.10.13

Npm 2.1.12

Thanks!

4 Answers 4

3

I ran into the same problem after upgrading ghost in a Digital Ocean Ubuntu instance.

cd /var/www/ghost  #or your custom ghost dir
ghost ls #lists your ghost configuration

Make sure the port number configured in your ghost's config file and the proxy_pass in your ghost site's nginx configuration files match.

Check the port number in /var/www/ghost/config.production.json matches the proxy_pass port in the nginx config files.

/var/www/ghost/system/files/<yourDomainName>.<extension>.conf
/var/www/ghost/system/files/<yourDomainName>.<extension>-ssl.conf

In my case I had to change 2368 to 2369 in the nginx config files to fix the issue.

Make sure you restart your ghost and nginx after you make the changes.

# restart your ghost site
cd /var/www/ghost/
ghost restart 
# restart nginx
sudo systemctl restart nginx

Hope this helps someone.

1
  • this fixed my problem when I was moving domains using ghost config url
    – snowbound
    Apr 24, 2020 at 11:38
0

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

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

Why?! =)

0

It looks as if the application is not running correctly. Probably a startup error has occurred, so that Ghost could not turn on the port. Therefore Nginx could not forward the requests to Ghost, and returns only "Bad Gateway".

You you could view the console log of PM2, then you can see exactly what went wrong.

2
0

To further troubleshoot pm2 I would remove nginx from the picture by modifying the Ghost config.js to the following:

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

and then try and start Ghost with pm2. Once you get Ghost running with pm2 add nginx back in.

We run several sites with pm2 and are very happy with it.

1
  • My problem with this approach is that I'm using deploy with Git, and every time, I stop the Pm2 proccess, run something like npm install --production and then start pm2 again. Dec 17, 2014 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.