【问题标题】:Ghost as an npm module not serving assets?Ghost 作为不提供资产的 npm 模块?
【发布时间】:2015-01-09 04:19:43
【问题描述】:

我在现有节点应用程序上使用 ghost 作为 npm 模块,基本上它是一个子应用程序。

所以我的应用程序在端口 9200 上运行,我为此设置了反向代理。

 location / {
    proxy_pass http://localhost:9200;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

然后我在我的主应用程序中配置了我的幽灵应用程序。

// server.js
ghost().then(function (ghostServer) {
    app.use(ghostServer.config.paths.subdir, ghostServer.rootApp);

    ghostServer.start(app);
});

// node_modules/ghost/config.js
production: {
    url: 'http://example.com/blog',
    mail: {},
    database: {
        client: 'sqlite3',
        connection: {
            filename: path.join(__dirname, '/content/data/ghost.db')
        },
        debug: false
    },

    server: {
        // Host to be passed to node's `net.Server#listen()`
        host: '127.0.0.1',
        // Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
        port: '2368'
    },
    paths: {
      contentPath: path.join(__dirname, '/blog/')
    }
}

由于 ghost 处理 /blog 路由,因此资产路径预计 /blog 会在路由中,因此我不得不将其从 /content 更改。

这在 http://example.com:9200/blog 上运行良好,但在为 /blog 设置反向代理之后

location /blog {
    proxy_pass http://localhost:9200;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

然后尝试转到http://example.com/blog,我只能得到html,这条路线上没有提供资产,我怀疑该位置需要包含像location /blog/*这样的通配符?

【问题讨论】:

    标签: node.js nginx ghost-blog


    【解决方案1】:

    以下帮助我解决了我的问题。

    Nginx - reverse proxy a Ghost blog with /subfolder redirect

    http://www.allaboutghost.com/how-to-install-ghost-in-a-subdirectory/

    location ^~ /blog {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
    
        proxy_pass http://127.0.0.1:2368;
        proxy_redirect off;
    }
    

    【讨论】:

      猜你喜欢
      • 2015-07-09
      • 1970-01-01
      • 1970-01-01
      • 2017-07-25
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2020-12-24
      • 1970-01-01
      相关资源
      最近更新 更多