我试图在我的主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);
});
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' });
});
1 回答
我've been having the same issue and first tried using Apache'的ProxyPass将
/blog
重定向到port 2368
,但发现其他问题这样做 .在尝试我的建议之前,您应该撤消使用
httpproxy
所做的任何更改 .似乎对我有用的是将您在
index.js
中的代码直接放入app.js
文件而不是您已经拥有的文件中 . 您将需要添加ghost errors变量并将parentApp
重命名为您的应用程序的名称,我将其称为yourAppName
所以它很清楚,但我的只是app
. 所以在app.js
内你可以放:您可能已经在app.js中声明了
ghost
和express
变量,因此您无需添加这些行 .现在,博客应该在config.js中指定的URL处可用 .