nginx fastcgi与django的问题(url中的双斜线?)

前端之家收集整理的这篇文章主要介绍了nginx fastcgi与django的问题(url中的双斜线?)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在部署我的第一个django应用程序.我从部署PHP-fpm熟悉Nginx和fastcgi.我无法让python识别网址.我也对如何进一步调试这一点感到茫然.我欢迎解决这个问题的方法和调试fastcgi问题的技巧.

目前我得到一个404页面,不管网址是什么,并且由于某种原因是双斜线
对于http://www.site.com/admin/

Page not found (404)
Request Method: GET
Request URL:    http://www.site.com/admin//

我的urls.py来自调试输出 – 在dev服务器中工作.

Using the URLconf defined in ahrlty.urls,Django tried these URL patterns,in this order:
^listings/
^admin/
^accounts/login/$
^accounts/logout/$

我的Nginx配置

server {
       listen   80;
       server_name  beta.ahrlty.com;
       access_log  /home/ahrlty/ahrlty/logs/access.log;
       error_log  /home/ahrlty/ahrlty/logs/error.log;

       location /static/ {
               alias  /home/ahrlty/ahrlty/ahrlty/static/;
               break;
       }

       location /media/ {
               alias /usr/lib/python2.6/dist-packages/django/contrib/admin/media/;
               break;
       }

       location / {
               include /etc/Nginx/fastcgi_params;
               fastcgi_pass 127.0.0.1:8001;
               break;
       }
}

和我的fastcgi_params

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的manage.py从命令行运行fastcgi.

python manage.py runfcgi method=threaded host=127.0.0.1 port=8080 pidfile=mysite.pid minspare=4 maxspare=30 daemonize=false

我很难调试这个.有人跳出来吗?

笔记

> Nginx版本:Nginx / 0.7.62
> Django svn trunk rev 13013

最佳答案
也许看看@L_301_3@的django文档.
我的熟悉问题的解决方案(但使用lighttpd)正在推出

FORCE_SCRIPT_NAME=""

在我的settings.py中.也给

FORCE_SCRIPT_NAME="/"

一试!

猜你在找的Nginx相关文章