【发布时间】: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