Nginx日常踩坑指南

iBit程序猿 2023年07月12日 1,427次浏览

踩坑1:Nginx location 和 proxy_pass 末尾/问题

序号访问URLlocation配置proxy_pass配置后端接收的请求备注
1http://ibit.tech/user/test.html/user/http://test1//test.html
2http://ibit.tech/user/test.html/user/http://test1/user/test.html
3http://ibit.tech/user/test.html/userhttp://test1/user/test.html
4http://ibit.tech/user/test.html/userhttp://test1///test.html
5http://ibit.tech/user/test.html/user/http://test1/haha//haha/test.html
6http://ibit.tech/user/test.html/user/http://test1/haha/hahatest.html

踩坑2:nginx 路径中多个斜杆问题

如果访问 https://ibit.tech//test.html 重定向到 https://ibit.tech/test.html

merge_slashes off;
rewrite (.*)//(.*) $1/$2 permanent;

参考资料