Nginx中的密码保护Django URL模式



我正在尝试基于URL密码保护我的Django网站的某个部分。假设我已经得到了我想要密码保护的URL /protected/section/ (URL也将接受URL参数,但我假设它们将在所有这些之后被处理)。

所以我把这个添加到我的Nginx配置:

location /protected/section/ {
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.demo.htpasswd;
}

我已经生成了这样的.htpasswd文件:

htpasswd -c /etc/nginx/.demo.htpasswd demo

所以现在当我访问http://mysite/protected/section/时,我得到密码提示,但是当我输入它时,我得到404错误。是否有另一行我需要添加,以获得请求被传递到Django(通过Gunicorn)像所有其他请求?我认为在身份验证之后,请求将被视为没有限制。

所以,这里是在我的myapp.conf文件中为我工作的相关位:

upstream appinstances {
  server 127.0.0.1:5001;
}
server {
  listen     80;
  server_name  myapp.example.com;
  location ^~/manage/ {
    satisfy any;
    auth_basic            "Restricted Area";
    auth_basic_user_file  /etc/linotp2/admins;
    deny all;
    proxy_pass              http://appinstances;
    proxy_redirect          off;
  }
... # the rest of the config
}

我的头在这上面撞了一会儿。

最新更新