加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

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

发布时间:2020-12-13 21:32:18 所属栏目:Nginx 来源:网络整理
导读:我试图在我的主Node.js项目的子目录上运行Ghost.它目前托管在azure网站上. 就像是: http://randomurlforpost.azurewebsites.net/blog 我按照这里的说明操作: https://github.com/TryGhost/Ghost/wiki/Using-Ghost-as-an-NPM-module 随着使用Ghost作为npm模

我试图在我的主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,{ target: 'http://localhost:2368' });
});
最佳答案
我一直有同样的问题,并首先尝试使用Apache的ProxyPass重定向/博客到端口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.help);
});

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

现在,博客应该在config.js中指定的URL处可用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读