【问题标题】:Password-protecting Django URL patterns in NginxNginx 中的密码保护 Django URL 模式
【发布时间】:2014-10-05 19:56:05
【问题描述】:

我正在尝试根据 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)?我认为在身份验证后,请求将被视为没有限制。

【问题讨论】:

    标签: django nginx ubuntu-12.04 gunicorn


    【解决方案1】:

    因此,以下是我的 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
    }
    

    我为此头疼了一会儿。希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-19
      • 2011-05-18
      • 1970-01-01
      • 2015-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-21
      相关资源
      最近更新 更多