Nginx的隱藏式跳轉能夠實現將請求跳轉到另外一個網站的頁面,而且瀏覽器中URL保持不變。Nginx配置中須要使用rewrite規則。下面提供兩個示例來講明這種跳轉需求的配置:php
1、配置示例1
將請求路徑https://kevin.com/data/test跳轉到https://rubao.com/data/test/test.html頁面。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、配置示例2
將訪問172.16.60.16:8082/m2/order/secretRecording的請求跳轉到172.16.60.28:8089/order/secretRecordingnginx
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; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; rewrite ^(.*)$ /order/secretRecording break; #先改寫URI地址 proxy_pass http://172.16.60.28:8089; #跳轉 } }