Nginx获得Bad Gateway的幽灵博客

时间:2014-12-16 17:50:23

标签: node.js nginx digital-ocean ghost-blog pm2

我的ghost应用程序正在使用502坏网关。 我在互联网上进行了研究,但没有找到答案。

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文件:

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";
    }
}

我创建了启用文件夹网站的符号链接:

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

我正在使用PM2启动Ghost APP:

pm2 start index.js

当我尝试使用以下方式启动Ghost APP时:

npm start

我可以看到博客,但是当我尝试使用pm2时,我的网关很糟糕。

我正在使用:

Ubunt 14.04 64bits

节点v0.10.13

Npm 2.1.12

谢谢!

4 个答案:

答案 0 :(得分:1)

在Digital Ocean Ubuntu实例中升级幽灵后,我遇到了同样的问题。

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

确保幽灵的配置文件中配置的端口号与幽灵站点的nginx配置文件中的 proxy_pass 相匹配。

检查端口号 /var/www/ghost/config.production.json与nginx配置文件中的 proxy_pass 端口匹配。

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

就我而言,我必须将nginx配置文件中的2368更改为2369以解决此问题。

请确保在进行更改后重新启动幽灵和nginx

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

希望这对某人有帮助。

答案 1 :(得分:0)

现在,也许,我找到了解决方案,但我不知道为什么。

我删除了PM2并安装了Forever,猜猜是什么,工作!

为什么? =)

答案 2 :(得分:0)

看起来应用程序运行不正常。可能发生了启动错误,因此Ghost无法打开端口。因此,Nginx无法将请求转发给Ghost,只返回&#34; Bad Gateway&#34;。

您可以查看PM2的控制台日志,然后您可以确切地看到出了什么问题。

答案 3 :(得分:0)

为了进一步解决pm2问题,我会通过修改Ghost config.js来删除图片中的nginx:

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'
    }

然后尝试使用pm2启动Ghost。一旦你使用pm2运行Ghost,就可以重新添加nginx。

我们使用pm2运行多个站点,并对此非常满意。