【Nginx】不同域名保持URL不变进行隐性跳转

TangLu 未命名 2019-11-29 16710 2

Nginx的隐性跳转可以实现将请求跳转到另一个网站的页面,并且浏览器中URL保持不变。

配置示例:将请求路径https://abc.com/home/test跳转到https://def.com/home/test/test.html页面

server {
    listen       443;
    server_name  abc.com;   
    location = /home/test {
        rewrite /home/test /home/test/test.html break;
        proxy_pass https://def.com;
    }
}

server {
    listen       443;
    server_name  abc.com;   
    location = /home/test {
        rewrite /home/test /home/test/test.html break;
        proxy_pass https://def.com;
    }
}



线上配置需求:访问https://polaris.abc.com/orion/group返回的内容和http://edf.com/user-portrait-sys/index.html一样

location  /orion {
  rewrite ^/(.*)  /user-portrait-sys/index.html break;
  proxy_pass https://res.huizecdn.com;
  }



线上配置需求:访问192.168.10.54:1054/v2/aliyun/secretRecording的请求跳转到10.160.2.100:8089/aliyun/secretRecording:

server {
       listen 1054;
       server_name 192.168.10.54;
       index   index.html index.php index.htm;
       location ~* ^/v2/aliyun/secretRecording {
                proxy_next_upstream error timeout http_503 http_504 http_502;
                proxy_connect_timeout 500s;
                proxy_read_timeout 500s;
                proxy_send_timeout 500s;
                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                rewrite  ^(.*)$  /aliyun/secretRecording break;  #先改写URI地址
                proxy_pass http://10.160.2.100:8089;  #跳转
       }
}

评论

精彩评论
2021-02-19 17:00:04

为何我这样配置后 直接404

2021-02-19 17:48:35

@頻率 @頻率:建议看下error日志,看报错的路径是啥