【问题标题】:Ghost Blog with Nginx getting Bad Gateway带有 Nginx 的 Ghost 博客获取错误网关
【发布时间】:2014-12-16 17:50:22
【问题描述】:

我的 Ghost 应用程序出现 502 错误网关。 我在整个互联网上进行了研究,但没有找到答案。

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

我的 Nginx suptar.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";
    }
}

我创建了指向文件夹 sites-enabled 的符号链接:

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 64 位

节点 v0.10.13

Npm 2.1.12

谢谢!

【问题讨论】:

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


    【解决方案1】:

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

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

    确保你ghost的配置文件中配置的端口号和你ghost站点的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 才能解决此问题。

    确保在进行更改后重新启动 ghost 和 nginx

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

    希望这对某人有所帮助。

    【讨论】:

    • 这解决了我在使用ghost config url移动域时遇到的问题
    【解决方案2】:

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

    我删除了 PM2 并安装了 Forever,你猜怎么着,工作!

    为什么?! =)

    【讨论】:

      【解决方案3】:

      看起来应用程序运行不正确。可能是出现了启动错误,导致 Ghost 无法打开端口。因此 Nginx 无法将请求转发给 Ghost,只返回“Bad Gateway”。

      您可以查看 PM2 的控制台日志,然后您可以确切地看到问题所在。

      【讨论】:

      • 这是 pm2 在日志中显示的错误:link 还有一件事,有一个无限循环显示此错误。
      • 貌似其他人也有同样的问题 PM2:ghost.org/forum/installation/…
      【解决方案4】:

      为了进一步解决 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 运行了多个站点,并且对它非常满意。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-29
      • 2020-09-26
      • 1970-01-01
      • 1970-01-01
      • 2014-03-29
      • 1970-01-01
      相关资源
      最近更新 更多