51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

nginx反向代理处理问号匹配

某URL通过nginx做反向代理,当前URL中存在问号特殊字符处理方法。

假设URL地址为https://www.whsir.com/index.php?m=api&f=23wh233

符号前使用\进行转义

nginx反向代理location精确匹配,仅暴露固定的URL接口
location = /index.php { if ($request_uri !~* ^/index.php\?m\=api\&f\=23wh233$) { return 404; } proxy_pass https://www.whsir.com/index.php?m=api&f=23wh233; }

|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 | location = /index.php { if ($request_uri !~* ^/index.php\?m\=api\&f\=23wh233$) { return 404; } proxy_pass https://www.whsir.com/index.php?m=api&f=23wh233; } |

如果想在index.php?m=api&f=23wh233后继续匹配,则通过location前缀匹配
location ^~ /index.php { if ($request_uri !~* /index.php\?m\=api\&f\=23wh233) { return 404; } proxy_pass https://www.whsir.com; }

|-------------|--------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 | location ^~ /index.php { if ($request_uri !~* /index.php\?m\=api\&f\=23wh233) { return 404; } proxy_pass https://www.whsir.com; } |

赞(0)
未经允许不得转载:工具盒子 » nginx反向代理处理问号匹配