https://blog.detectify.com/2020/11/10/common-nginx-misconfigurations/
很有用的文章,讲nginx容易配置不当导致易受攻击的地方。
捡几个重要的说说:
- 一定要写清楚
root /path/to/html;
,不要把敏感文件放在这个路径里
- 反向代理
location
要以 /
结尾
location /api/ { # 不能写成 /api
proxy_pass http://apiserver/v1/;
}
- 使用
$request_uri
而不是 $uri
或 $document_uri
,比如
location / {
return 302 https://viegg.com$request_uri; # 不能写成 #uri
}