nginx 重定向所有带或不带扩展名的文件,少数除外
nginx redirects all files with or without extensions except a few
如何匹配所有带有 或不带有 扩展名的文件,扩展名为 txt、pdf、jpeg 的文件除外。
在我的 Nginx 配置中,这会无限制地下载所有文件。
location ~ .+(?<!\.pdf|\.txt|\.jpeg)$ {
auth_request /auth.php;
error_page 401 = @login;
}
谢谢
定义两个位置怎么样?例如
location ~ \.(pdf|txt|jpeg)$ {
# handle those with the extension pdf, txt, jpeg
}
location / {
# handle all files with or without extension
}
已解决我 auth.php 未作为异常包含在内,这会导致循环。
location ~ .+(?<!/|auth.php|.txt|.pdf|.jpeg|.jpg|.png)$ {
auth_request /auth.php;
error_page 401 = @login;
}
如何匹配所有带有 或不带有 扩展名的文件,扩展名为 txt、pdf、jpeg 的文件除外。
在我的 Nginx 配置中,这会无限制地下载所有文件。
location ~ .+(?<!\.pdf|\.txt|\.jpeg)$ {
auth_request /auth.php;
error_page 401 = @login;
}
谢谢
定义两个位置怎么样?例如
location ~ \.(pdf|txt|jpeg)$ {
# handle those with the extension pdf, txt, jpeg
}
location / {
# handle all files with or without extension
}
已解决我 auth.php 未作为异常包含在内,这会导致循环。
location ~ .+(?<!/|auth.php|.txt|.pdf|.jpeg|.jpg|.png)$ {
auth_request /auth.php;
error_page 401 = @login;
}