Reputation: 2554
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!
Upvotes: 1
Views: 2144
Reputation: 291
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.
Upvotes: 3
Reputation: 471
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.
Upvotes: 0
Reputation: 11
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.
Upvotes: 0
Reputation: 2554
Now, maybe, i found the solution, but i don't know why yet.
I deleted PM2 and installed Forever, guess what, WORKS!
Why?! =)
Upvotes: 0