登录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),两个服务器的配置在提供 帖子的结尾。我正在访问我的django应用程序127.0.0.1:8003 /.
所以,127.0.0.1:8003 / admin /打开django管理员登录表单。 1)输入用户名/密码,按“登录”重定向到(出于某种未知原因?)127.0.0.1/ 管理员,因此没有任何结果,因为没有服务器监听 在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 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/;
}
}
}
欢呼声, 到
答案 0 :(得分:1)
您的设置不正确。 Django认为它在端口80上运行。在第一个HTTP响应中查看这一行:
Location: http://127.0.0.1/admin/
不幸的是,我现在无法理解为什么会这样。在这种情况下,我更喜欢用调试器来完成相关的Django代码。
答案 1 :(得分:1)
返回的Location
标头不正确:
Location: http://127.0.0.1/admin/
这显然缺少端口号。不幸的是,很难确切地知道这是从哪里来的。您可能会遇到Nginx或Apache自动更改Location
标头。我建议你做以下事情,看看问题出现在哪里:
忍者编辑!
不确定这是否会有所帮助,但似乎Nginx中有一个选项可以忽略重定向中的端口号。该网址已失效,因此我将其从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的。
答案 2 :(得分:1)
再次感谢你的帮助!
结果显示了解决方案here:将proxy_set_headerHost $host;
更改为proxy_set_headerHost $host:$server_port;
就行了!