[英]Django admin authentication failure
首次按下“登錄”按鈕時,登錄django admin失敗,但是再次按下“返回”和“登錄”-成功登錄用戶。
我將在此處使用zc.buildout部署Django應用,其設置類似於http://www.meppum.com/2009/jan/17/installing-django-ubuntu-intrepid/ 。 Nginx(在127.0.0.1:8003上監聽)的運行超出了Apache(在127.0.0.1:8001上監聽)的運行范圍,文章結尾處提供了這兩個服務器的配置。 我正在以127.0.0.1:8003/的身份訪問我的Django應用程序。
因此,127.0.0.1:8003/admin/將打開django管理員登錄表單。 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配置。
任何想法如何使管理員登錄表單立即工作?
干杯!
至
PSconfigs:
apache vhost配置:
<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/;
}
}
}
歡呼
您的設置不正確。 Django認為它運行在端口80上。在第一個HTTP響應中查看以下行:
Location: http://127.0.0.1/admin/
不幸的是,我現在不明白為什么會這樣。 在這種情況下,我更喜歡使用調試器逐步調試相關的Django代碼。
@Eugene Morozov指出了問題的最終結果,但我認為解決方案更深入。
返回的Location
標頭不正確:
Location: http://127.0.0.1/admin/
這顯然缺少端口號。 不幸的是,很難確切地說出它的來源。 您可能會碰巧通過Nginx或Apache來自動更改Location
標頭。 我建議執行以下操作以查看問題的根源:
忍者編輯!
不知道這是否有幫助,但是Nginx中似乎有一個選項可以忽略重定向中的端口號。 URL已死,所以我要從這里粘貼。
http://wiki.codemongers.com/NginxHttpCoreModule#port_in_redirect
syntax: port_in_redirect [ on|off ]
default: port_in_redirect on
context: http, server, location
指令允許或阻止nginx處理的重定向中的端口指示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.