在URLS问题Django的双斜杠(多个Web服务器,Apache和Nginx)

看一个例子:加载一个example.com,点击一个链接到/ test的链接,而不是去http:// example.com/test/去http:// www.example.net //testing/

或者,如果您login,自动生成的djangopipe理部分的login表单发布到// admin而不是admin。

似乎这是一个Django的问题,但我改变的唯一的事情是nginx

几个额外的笔记(添加10月31日):

  • 这个问题看起来非常类似于https://serverfault.com/questions/134863/nginx-fastcgi-problems-with-django-double-slashes-in-url,但不同的是,我得到斜线添加项目的根之前“// admin /”和“admin //”。 那里的成功解决scheme并没有帮助我。
  • 我正在使用Django的当前SVN版本。

这里是nginx的fastcgi_conf:

#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; 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 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_param PATH_INFO $fastcgi_script_name; # PHP only, required if PHP was built with --enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200; 

Django项目configuration

 server { listen 80; server_name www.site.net; location / { fastcgi_pass unix:/path/to/site/server.sock; include fastcgi.conf; access_log /var/log/nginx_django.log main; } location ^~ /admin/$ { fastcgi_pass unix:/path/to/site/server.sock; include fastcgi.conf; access_log /var/log/nginx_django.log main; } location ~* ^.+\.(mpg|avi|mp3|swf|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|txt|tar|mid|midi|wav|rtf|mpeg)) $ { root /path/to/site/media; limit_rate 2000K; access_log /var/log/nginx_django_media.log download; access_log off; } location ^~ /static/ { root /path/to/site; access_log /var/log/nginx_django_static.log download; expires 30d; } location /403.html { root /opt/nginx; access_log off; } location /401.html { root /opt/nginx; access_log off; } location /404.html { root /opt/nginx; access_log off; } location = /_.gif { empty_gif; access_log off; } } 

 fastcgi_param SCRIPT_NAME ''; 

这为我解决了问题。