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

时间:2015-01-23 04:16:30

标签: node.js azure nginx ghost-blog

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

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

随着新增使用Ghost作为npm模块,我还需要Nginx还是Apache?截至目前,我的主站点运行在localhost:3000上,Ghost实例运行在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);
});




编辑:我能够使用 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' });
});




1 个答案:

答案 0 :(得分:2)

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

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

对我来说似乎有用的是将index.js中的代码直接放入app.js文件中,而不是放在那里已有的代码中。您需要添加ghost错误变量并将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处可用。