首页 > 解决方案 > 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.

标签: nginx.htpasswd

解决方案


这将使 /test/ 无需任何身份验证即可响应,并且所有其他请求都需要身份验证。

server {

  auth_basic      "Administrator Login";
  auth_basic_user_file  /var/www/static/.htpasswd;

  location /test/ {
    auth_basic off;
  }

}

推荐阅读