我在settings.py中这样设置LOGIN_URL:
LOGIN_URL = '/login/'
在 urls.py 我和这个 URLConf 中:
(r'^$', 'agent.index.redirect'), (r'^login/$', 'django.contrib.auth.views.login', {'template_name':'login.html'}),
agent.index.redirect 视图是这样的:
@login_required def redirect(request): ...
我像这样运行我的 Django 网站:
python manage.py runfcgi host=127.0.0.1 port=8090 --settings=settings
nginx.conf 是这样的:
user nobody nobody; worker_processes 5; #error_log /var/log/nginx/error_log info; events { worker_connections 1024; use epoll; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] ' '"$request" $status $bytes_sent ' '"$http_referer" "$http_user_agent" ' '"$gzip_ratio"'; client_header_timeout 10m; client_body_timeout 10m; send_timeout 10m; connection_pool_size 256; client_header_buffer_size 1k; large_client_header_buffers 4 2k; request_pool_size 4k; gzip on; gzip_min_length 1100; gzip_buffers 4 8k; gzip_types text/plain; output_buffers 1 32k; postpone_output 1460; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 75 20; ignore_invalid_headers on; index index.html; server { listen 80; server_name localhost; root /web/agent; location /static { alias /web/agent/media; access_log off; expires 30d; } location /media { alias /web/agent/admin_media; access_log off; expires 30d; } location / { # host and port to fastcgi server fastcgi_pass 127.0.0.1:8090; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param QUERY_STRING $query_string; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_pass_header Authorization; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param HTTPS $https if_not_empty; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_connect_timeout 30s; fastcgi_send_timeout 30s; fastcgi_read_timeout 30s; fastcgi_buffer_size 128k; fastcgi_buffers 8 128k;#8 128 fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; } #access_log /usr/local/nginx/logs/access_log main; #error_log /usr/local/nginx/logs/error_log; } }
当我访问 [http://localhost] 时,会有一个重定向循环。而nginx的access.log是这样的:
127.0.0.1 - - [28/Feb/2013:18:13:51 +0800] "GET / HTTP/1.1" 302 5 "-" "Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130220 Firefox/17.0" 127.0.0.1 - - [28/Feb/2013:18:13:51 +0800] "GET /login/?next=// HTTP/1.1" 302 5 "-" "Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130220 Firefox/17.0" 127.0.0.1 - - [28/Feb/2013:18:13:51 +0800] "GET /login/?next=/login//%3Fnext%3D// HTTP/1.1" 302 5 "-" "Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130220 Firefox/17.0" 127.0.0.1 - - [28/Feb/2013:18:13:51 +0800] "GET /login/?next=/login//%3Fnext%3D/login//%253Fnext%253D// HTTP/1.1" 302 5 "-" "Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130220 Firefox/17.0" 127.0.0.1 - - [28/Feb/2013:18:13:51 +0800] "GET /login/?next=/login//%3Fnext%3D/login//%253Fnext%253D/login//%25253Fnext%25253D// HTTP/1.1" 302 5 "-" "Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130220 Firefox/17.0" ...and so on.
任何人都可以帮助解决这个问题吗?