nginx - Password lock site except for certain routes running nginx
问题描述
We have a server we don't want Google to index or anyone else to get access to unless they have a password.
How can I directory lock the entire server except for very specific routes used by external scanning services?
For instance, example.com/test should output a response from the framework without blocking but any other URL should ask for a password to get any content response.
I know how to do this with Apache using .htpasswd
, but I need to be able to do it on nginx while whitelisting a specific route.
解决方案
这将使 /test/ 无需任何身份验证即可响应,并且所有其他请求都需要身份验证。
server {
auth_basic "Administrator Login";
auth_basic_user_file /var/www/static/.htpasswd;
location /test/ {
auth_basic off;
}
}
推荐阅读
- python - 如何从 SQL Server 获取日期和时间到 python?
- java - 无法将 UTC 转换为本地时间
- rest - HttpClient 无法从运行超过一小时的 rest api 获得任何响应
- javascript - 将参数从一个文件的应用程序获取功能传递到另一个文件
- android - 如何在 Kotlin 中设置 ViewDragHelper 灵敏度?
- python - 如何正确使用 tf.function 与 TensorFlow 数据集
- excel - Range.Calculate 不更新范围内的值
- python-3.x - python:获取pandas计算列中常见模式的出现
- python - 如何在 linux 服务器中设置新用户以使用 Python?
- java - guava multimap 到响应模型的映射结果