【发布时间】:2019-02-16 21:26:09
【问题描述】:
我在 nginx 后面的 web 应用程序不应该收到任何包含相对路径的 url,例如 ../,直接在 Nginx 级别拒绝它们会更安全。
尝试了这个配置,但不工作:
location ~ \.\.\/ {
return 400;
}
带有测试用例:
printf "GET /web/../play/find.js HTTP/1.1\r\nHost: www.example.com\r\n\r\n" | nc 127.0.0.1 80
【问题讨论】:
-
您的
location规则将不起作用,因为此时nginx已经解析了任何..路径元素。您需要使用map或if块检查$request_uri。 -
@RichardSmith 你是对的!
标签: nginx nginx-location