Posted in Servers onApril 07, 2022
Nginx的隐藏式跳转可以实现将请求跳转到另一个网站的页面,并且浏览器中URL保持不变。Nginx配置中需要使用rewrite规则。下面提供两个示例来说明这种跳转需求的配置:
一、Nginx隐藏式跳转配置示例1
将请求路径https://3water.com/data/test跳转到https://jb51.com/data/test/test.html页面。
server {
listen 443;
server_name 3water.com;
access_log /data/nginx/logs/3water.com-access.log main;
error_log /data/nginx/logs/3water.com-error.log;
ssl on;
ssl_certificate /data/nginx/ssl/3water.com.crt;
ssl_certificate_key /data/nginx/ssl/3water.com.key;
ssl_session_timeout 5m;
location = /data/test {
rewrite /data/test /data/test/test.html break;
proxy_pass https://jb51.com;
}
}
二、Nginx隐藏式跳转配置示例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;
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; #跳转
}
}
Nginx隐藏式跳转(浏览器URL跳转后保持不变)
- Author -
散尽浮华- Original Sources -
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@