Node.js Ghost作为npm模块不提供资产?
我使用ghost作为现有节点应用程序上的npm模块,基本上它是一个子应用程序 所以我的应用程序运行在端口9200上,我已经为此设置了一个反向代理Node.js Ghost作为npm模块不提供资产?,node.js,nginx,ghost-blog,Node.js,Nginx,Ghost Blog,我使用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_
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;
}
然后我在主应用程序中配置了我的ghost应用程序
// 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/*
?以下内容帮助我解决了问题
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;
}