Nginx配置教程:不同域名保持URL不变进行隐性跳转

2020年11月23日14:34:39 发表评论 1,176
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;  #跳转 
       } 
}        
    

    发表评论

    :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: