有人知道如何将proxy_pass设置为精确路径。
我有与节点服务器配合使用的 React 应用程序。
const express = require('express'),
app = express(),
path = require('path'),
bodyParser = require('body-parser'),
router = require('./routes/route.index.js'),
react = require('./routes/routes.app.js'),
history = require('connect-history-api-fallback');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, './assets')));
app.use(history());
router(app, react); // app.get(*, (req, res) => { res.sendFile(....) })
app.listen(process.env.CLIENT_FRONTEND_PORT, () => console.info(`listen ${process.env.CLIENT_FRONTEND_PORT}`));
我有 2 个域 1 个域很好用,但第二个我需要将 proxy_pass 设置为精确的 React 路由器路径。
示例:
example1.com/contact - works
example2.com/ - should open /contact router immediately.
我尝试过第二个域:
location ^~ / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://frontend:8880/contact;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|pdf|ppt|txt|bmp|rtf|ttf|svg|js)$ {
expires 2d;
add_header Cache-Control public;
}
和其他人使用 nginx 正则表达式,但一直收到错误,因为 url example2.com/build/.......js 找不到 js 文件
有什么线索吗?