我已经配置nginx的所有请求传递到节点:与Express和nginx的Vue公司路由器的历史模式,反向代理
server {
listen 80;
server_name domain.tld;
location/{
proxy_pass http://localhost:3000;
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;
}
}
在服务器上我有运行快速哪些服务器我Vue的索引文件节点的应用程序。
app.get('/', (req, res) => {
res.sendFile(`${__dirname}/app/index.html`);
});
我想使用HTML5历史模式Vue的路由器,所以我设置的路由器设置mode: 'history'
。我安装connect-history-api-fallback,并将其设置:
const history = require('connect-history-api-fallback');
app.use(history());
的路由工作正常,如果用户首先点击http://domain.tld
。但是,如果直接访问子路由或刷新页面,则会出现未找到的错误。
如何更改我的配置?
使用节点应用程序来提供文件是明智吗?用它是不是更好? nginx在资源方面? – jntme