情况一:
重定向至某个页面,如index.html页面,但是url中的参数会丢失

使用error_page ,且 proxy_intercept_errors on;一定要配置
配置:
location / {
proxy_intercept_errors on;
proxy_pass http://upstream_1;
error_page 404 http://$server_name/index.html
}
情况二:
重定向需要把原来老的url中的参数也带入
如下图

使用nginx history模式 try_files
配置:
location / {
try_files $uri $uri/ /index.html;
proxy_pass http://upsteam_1;
}
本文探讨了Nginx中如何配置error_page和try_files来避免URL参数丢失,并介绍如何在重定向时保留原有参数。第一部分讲解了使用proxy_intercept_errorson配合error_page处理404错误,第二部分则展示了利用history模式的try_files正确处理参数传递的方法。
2336

被折叠的 条评论
为什么被折叠?



