要实现不更改域名但重定向流量的解决方法,可以使用以下代码示例:
const express = require('express');
const app = express();
app.get('*', (req, res) => {
const redirectURL = 'https://example.com'; // 重定向的URL
res.redirect(redirectURL);
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
在Nginx的配置文件中,可以添加以下代码:
server {
listen 80;
server_name example.com;
location / {
proxy_pass https://newdomain.com; // 重定向的URL
proxy_set_header X-Real-IP $remote_addr;
}
}
以上代码将请求example.com的流量重定向到newdomain.com。
请注意,以上代码示例仅为演示目的,实际使用时需要根据具体需求进行修改。