简体   繁体   English

Django使用Ngnix + Gunicorn进行基本身份验证失败

[英]Django Fails with Basic Auth with Ngnix + Gunicorn

I'm trying to load balance 2 gunicorn servers with nginx. 我正在尝试使用nginx平衡2个gunicorn服务器。 I am required to have basic auth on the application, so I thought I would stick the auth on the nginx server. 我需要在应用程序上具有基本身份验证,因此我认为我会将身份验证粘贴在nginx服务器上。

However for some reason my Django completely fails when I enable basic auth the nginx server. 但是由于某种原因,当我启用nginx服务器的基本身份验证时,Django完全失败。 Everything works perfectly after disabling basic in my nginx conf. 在我的nginx conf中禁用basic后,一切工作正常。

Here is my nginx conf. 这是我的nginx conf。

upstream backend {
    server 10.0.4.3;
    server 10.0.4.4;
}




server {
    listen 80;


    location / {
         proxy_pass http://backend;
     proxy_set_header X-Forwarded-Host $server_name;
            proxy_set_header X-Real-IP $remote_addr;
            add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
             auth_basic "Restricted";
           auth_basic_user_file /etc/nginx/.htpasswd;
            proxy_set_header REMOTE_USER $remote_user;

    }

    location /orders
    {
     auth_basic "off" ;
    }
}

This is the error I'm getting: 这是我得到的错误:

Error importing module keystone_auth.backend: "No module named keystone_auth.backend"

I thought it might be some headers that I need to pass through. 我认为可能是我需要传递的一些标头。 Is there another way to get basic auth on Django bearing in mind that it needs to be load balanced. 考虑到需要平衡负载,还有另一种方法可以在Django上获得基本身份验证。 Or is my ngnix config missing some stuff? 还是我的ngnix配置丢失了一些东西?

The keystone_auth.backend had mistakenly be included from another settings file, I was still unable to get BasicAuth working, but eventually solved the issue by writing my own Auth Back end as described here. 错误地将keystone_auth.backend包含在另一个设置文件中,我仍然无法使BasicAuth正常工作,但是最终通过编写我自己的Auth Back端来解决此问题,如下所述。

https://docs.djangoproject.com/en/dev/topics/auth/customizing/ https://docs.djangoproject.com/en/dev/topics/auth/customizing/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM