2010-02-01 97 views
1

登录到admin界面时,“登录”按钮被按下第一 时间,但按“后退”和“登录再​​次失败 - 记录用户在 成功Django管理认证失败

我部署Django应用程序与zc.buildout在这里,设置类似 这里描述的内容http://www.meppum.com/2009/jan/17/installing-django-ubuntu-intrepid/。 Nginx(在127.0.0.1:8003上侦听)超出Apache(在127.0.0.1:8001上侦听 ),两台服务器的配置提供在 结尾的帖子我正在访问我的django应用程序127.0.0.1:8003/。

所以,127.0.0.1:8003/admin/打开django admin登录表单。 1)输入用户名/密码,按“登录”重定向到(出于某种未知原因?)127.0.0.1/ admin,因此没有任何结果,因为没有服务器在80端口上监听 。 HTTP跟踪(后点击登录:http://127.0.0.1:8003/admin/

POST /admin/ HTTP/1.1 
Host: 127.0.0.1:8003 
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.17) Gecko/2010010604 Ubuntu/9.04 (jaunty) Firefox/3.0.17 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-us,en;q=0.5 
Accept-Encoding: gzip,deflate 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive: 300 
Connection: keep-alive 
Referer: http://127.0.0.1:8003/admin/ 
Cookie: JSESSIONID=0D287C17FBA82223AB7D5884EA534967; sessionid=c65c7af8ebde9e6bdf9c739a731d376b 
Content-Type: application/x-www-form-urlencoded 
Content-Length: 55 
username=to&password=password&this_is_the_login_form=1 

HTTP/1.x 302 FOUND 
Server: nginx/0.8.29 
Date: Mon, 01 Feb 2010 10:27:44 GMT 
Content-Type: text/html; charset=utf-8 
Connection: keep-alive 
Expires: Mon, 01 Feb 2010 10:27:44 GMT 
Vary: Cookie 
Etag: "d41d8cd98f00b204e9800998ecf8427e" 
Cache-Control: max-age=0 
Set-Cookie: sessionid=9db437da69c359136786696f90ba89f2; expires=Mon, 15-Feb-2010 10:27:44 GMT; Max-Age=1209600; Path=/ 
Last-Modified: Mon, 01 Feb 2010 10:27:44 GMT 
Location: http://127.0.0.1/admin/ 
Content-Length: 0 

2)按浏览器的后退,和“登录”按钮再次(或 按下浏览器的“返回”和“刷新”)日志中成功地。 HTTP跟踪:

POST /admin/ HTTP/1.1 
Host: 127.0.0.1:8003 
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.17) Gecko/2010010604 Ubuntu/9.04 (jaunty) Firefox/3.0.17 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-us,en;q=0.5 
Accept-Encoding: gzip,deflate 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive: 300 
Connection: keep-alive 
Referer: http://127.0.0.1:8003/admin/ 
Cookie: JSESSIONID=0D287C17FBA82223AB7D5884EA534967; sessionid=9db437da69c359136786696f90ba89f2 
Content-Type: application/x-www-form-urlencoded 
Content-Length: 55 
username=to&password=password&this_is_the_login_form=1 

HTTP/1.x 200 OK 
Server: nginx/0.8.29 
Date: Mon, 01 Feb 2010 10:52:02 GMT 
Content-Type: text/html; charset=utf-8 
Transfer-Encoding: chunked 
Connection: keep-alive 
Expires: Mon, 01 Feb 2010 10:52:02 GMT 
Vary: Cookie 
Etag: "3355a46fb32d7cb6ab21262c359d9eec" 
Cache-Control: max-age=0 
Last-Modified: Mon, 01 Feb 2010 10:52:02 GMT 

看起来这是一个cookie相关的问题,但是,我想,中 根本问题还不如位于apache的和/或nginx的配置为好。

任何想法如何使管理员登录表单立即工作?

干杯!

P.S.configs:

apache的虚拟主机配置:

<VirtualHost *:8001> 

    <Directory /home/toinbis/Desktop/programming/project/runtime/ 
htdocs/django_wsgi/> 
     Order deny,allow 
     Allow from all 
    </Directory> 

    WSGIDaemonProcess tsd user=www-data group=www-data threads=25 
    WSGIProcessGroup tsd 

    WSGIScriptAlias//home/toinbis/Desktop/programming/project/ 
runtime/htdocs/django_wsgi/djproject.wsgi 

    LogLevel warn 
    ErrorLog /home/toinbis/Desktop/programming/project/runtime/logs/ 
apache_tsd_error.log 
    CustomLog /home/toinbis/Desktop/programming/project/runtime/logs/ 
apache_tsd_access.log combined 

    ServerName localhost 
</VirtualHost> 

nginx的配置:

daemon off; 
#user www-data; 
worker_processes 2; 

error_log /home/toinbis/Desktop/programming/project/runtime/logs/ 
nginx_general_error.log; 
pid  /home/toinbis/Desktop/programming/project/runtime/var/pids/ 
nginx.pid; 

events { 
    worker_connections 1024; 
    #server_names_hash_bucket_size: 128; 

} 

http { 
    include  /home/toinbis/Desktop/programming/project/runtime/ 
etc/nginx_conf/mime.types; 
    default_type application/octet-stream; 

    access_log /home/toinbis/Desktop/programming/project/runtime/logs/ 
nginx_access.log; 
    error_log /home/toinbis/Desktop/programming/project/runtime/logs/ 
nginx_error.log; 

    sendfile  on; 
    tcp_nopush  on; 

    #keepalive_timeout 0; 
    keepalive_timeout 2; 
    tcp_nodelay  on; 

    server_names_hash_bucket_size 128; 
    #server_name_hashes 128; 
    gzip on; 
    gzip_comp_level 2; 
    gzip_proxied any; 
    gzip_disable "MSIE [1-6]\.(?!.*SV1)"; #iš ubuntu 
    gzip_types text/plain text/css application/x-javascript text/xml 
application/xml application/xml+rss text/javascript; 

upstream backend { 
    server 127.0.0.1:8001; 

} 

server { 
      listen 8003; 
      server_name localhost; 

      error_log /home/toinbis/Desktop/programming/project/ 
runtime/logs/project_nginx_error.log; 
      access_log /home/toinbis/Desktop/programming/project/ 
runtime/logs/project_nginx_access.log; 

      location/{ 
         proxy_pass http://backend/; 
         include  /home/toinbis/Desktop/programming/ 
project/runtime/etc/nginx_conf/nginx_proxy_1.conf; 
      } 

      location /media/ { 
         root /home/toinbis/Desktop/programming/project/ 
src/tsd/core/; 
      } 

} 
} 

欢呼声, 到

回答

1

@Eugene Morozov指出了问题的最终结果,但我认为解决方案更深入。

返回的Location头是不正确的:

Location: http://127.0.0.1/admin/ 

这显然是缺失的端口号。不幸的是,很难确切地知道这是从哪里来的。您可能会遇到Nginx或Apache自动更改Location标题。我建议你做下面的事情,看看问题出在哪里:

  • 在你每次登录前清除你的cookies,否则你可能会得到误报。
  • 直接进入你的Apache实例,看看问题是否存在。
    • http://127.0.0.1:8001/admin/
    • 如果该位置头不有它的端口:
      • 火了一些随机端口Django开发服务器(8005为例),看看问题是否仍然存在:
        • 如果问题仍然存在,那么在您的代码中。
        • 如果问题没有持续存在,Apache可能会做些奇怪的事情,或者WSGI/Django没有获取确定端口号所需的全部信息。
          • 确保wsgi脚本和django应用程序都可以在环境中看到端口号。
    • 如果位置标头中有一个端口:
      • Nginx的被汽提其关闭出于某种原因。
      • 尝试将Apache从循环中删除,您可能不需要它。
        • 启动Django作为FastCGI服务器,并将Nginx连接到Apache而不是Apache。
          • 这实际上会降低服务器上的一些开销(较少的请求传递,额外的线程,内存使用等)。
          • 相当不错的设置指南over here

忍者编辑!
不知道这是否会有所帮助,但Nginx似乎有一个选项可以忽略重定向中的端口号。该URL已经死了,所以我从over here上粘贴了这个。

http://wiki.codemongers.com/NginxHttpCoreModule#port_in_redirect

syntax: port_in_redirect [ on|off ] 
default: port_in_redirect on 
context: http, server, location 

指令允许或阻止端口在由 nginx的处理重定向 指示。

+0

哇,很好的回答!是“作为FastCGI服务器启动Django并将Nginx连接到Apache而不是Apache”。部署的全面报价?任何测试显示可以通过使用fastcgi而不是apache_modwsgi保存多少开销?会让你知道问题的追踪是怎么回事。 – toinbis 2010-02-01 19:07:40

+1

我不知道任何基准,只是常识。如果你不需要,为什么要运行两个完整的Web服务器? (假设你的项目不是很大,在这种情况下有理由这样做。) – 2010-02-01 20:03:49

+0

Apache只能正常工作,没关系,所以“Nginx由于某种原因将其剥离”是一个较低层次的原因。我深入了解nginx配置......再次感谢! – toinbis 2010-02-01 20:37:46

1

您的设置不正确。 Django的认为,在端口运行在第一HTTP响应80.看这句话:

Location: http://127.0.0.1/admin/ 

不幸的是,我现在不能为什么会这样理解。在这种情况下,我更愿意使用调试器逐步完成相关的Django代码。

+0

尤金,谢谢你的帮助。我现在正在尝试调试...开发服务器似乎在相同的设置下运行良好... – toinbis 2010-02-01 16:45:25

1

Euge,詹姆斯,

非常感谢您的帮助再次!

解决方案竟然被描述为here:将proxy_set_headerHost $host;更改为proxy_set_headerHost $host:$server_port;诀窍!