繁体   English   中英

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

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

我试图在主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' }); }); 

我一直遇到相同的问题,并且首先尝试使用Apache的ProxyPass将/blog重定向到port 2368但发现这样做的其他问题。

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

似乎对我app.js是将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上找到。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM