运行 Ghost 在我的主 Node.js 应用程序的子目录中

Run Ghost in a subdirectory of my main Node.js application

我正在尝试 运行 Ghost 在我的主 Node.js 项目的子目录上。它目前托管在 Azure 网站上。
就像是: http://randomurlforpost.azurewebsites.net/blog

我按照此处的说明操作: https://github.com/TryGhost/Ghost/wiki/Using-Ghost-as-an-NPM-module

新增了使用 Ghost 作为 npm 模块的功能,我还需要 Nginx 还是 Apache?截至目前,我的主站点 运行ning 在 localhost:3000 上,Ghost 实例 运行ning 在 localhost:2368.

我已经尝试对说明中所述的代码部分进行各种修改,但是我没有成功。

//app.js, is there a specific place to put this?

var ghost = require('ghost');
ghost().then(function (ghostServer) {
    ghostServer.start();
});

//config.js
    development: {
        url: 'http://localhost:3000/blog',
        database: {
            client: 'sqlite3',
            connection: {
            filename: path.join(__dirname, '/content/data/ghostdev.db')
            },
            debug: false
        },
        server: {
            host: '127.0.0.1',
            port: '2368'
        },
        paths: {
            contentPath: path.join(__dirname, '/content/'),
        }
    },
//index.js
ghost().then(function (ghostServer) {

    parentApp.use(ghostServer.config.paths.subdir,ghostServer.rootApp);

    // Let ghost handle starting our server instance.
    ghostServer.start(parentApp);
}).catch(function (err) {
    errors.logErrorAndExit(err, err.context, err.help);
});

EDIT:我能够使用 http-proxy 路由流量,但它会将其路由到 localhost:2368/blog (不存在)关于如何防止这种情况的任何想法?

var httpProxy = require('http-proxy');
var blogProxy = httpProxy.createProxyServer();
var ghost     = require('ghost');
var path      = require('path');

// Route /blog* to Ghost
router.get("/blog*", function(req, res, next){ 
    blogProxy.ws(req, res, { target: 'http://localhost:2368' });
});

我遇到了同样的问题,首先尝试使用 Apache 的 ProxyPass 将 /blog 重定向到 port 2368,但发现了其他问题。

在尝试我的建议之前,您应该撤消使用 httpproxy 所做的任何更改。

似乎对我有用的方法是将 index.js 中的代码直接放入 app.js 文件中,而不是将其中已有的代码放入其中。您将需要添加 ghost errors 变量并将 parentApp 重命名为您的应用程序名称,我将其命名为 yourAppName 这样很清楚,但我的只是 app。所以在 app.js 里面你可以放:

var yourAppName = express();
var ghost = require('ghost');
var ghosterrors = require('ghost/core/server/errors')

ghost().then(function(ghostServer) {
  yourAppName.use(ghostServer.config.paths.subdir, ghostServer.rootApp);

  ghostServer.start(yourAppName);
}).catch(function(err) {
  errors.logErrorAndExit(err, err.context, err.help);
});

您可能已经在 app.js 中声明了 ghostexpress 变量,因此您不需要添加这些行。

博客现在应该可以在 config.js 中指定的 URL 访问。