Nginx隐藏式跳转(浏览器URL跳转后保持不变) - 运维笔记
Nginx的隐藏式跳转可以实现将请求跳转到另一个网站的页面,并且浏览器中URL保持不变。Nginx配置中需要使用rewrite规则。下面提供两个示例来说明这种跳转需求的配置:
一、配置示例1 将请求路径https://kevin.com/data/test跳转到https://rubao.com/data/test/test.html页面。
server {
listen 443;
server_name kevin.com;
access_log /data/nginx/logs/kevin.com-access.log main;
error_log /data/nginx/logs/kevin.com-error.log;
ssl on;
ssl_certificate /data/nginx/ssl/kevin.com.crt;
ssl_certificate_key /data/nginx/ssl/kevin.com.key;
ssl_session_timeout 5m;
location = /data/test {
rewrite /data/test /data/test/test.html break;
proxy_pass https://rubao.com;
}
二、配置示例2 将访问172.16.60.16:8082/m2/order/secretRecording的请求跳转到172.16.60.28:8089/order/secretRecording
server {
listen 8082;
server_name 172.16.60.16;
index index.html index.php index.htm;
location ~* ^/m2/order/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;