Empty 'current url' for Django deployed with Nginx and fastcgi

末鹿安然 提交于 2019-11-30 16:00:27

问题


When I query this url

http://mywebsite.com/foos/ 

Django give me :

Page not found (404)
Request Method:     GET
Request URL:    http://mywebsite.com/foos//    
The current URL, , didn't match any of these.

the errors :
- in Request URL it add me '/' at the end,
- in current URL is empty.

my spec :
I run my django website with nginx as reverseproxy to the fast_cgi.

Here my website conf for nginx :

server {
         listen   80;
         server_name  mywebsite.com;


             location / {
                     fastcgi_pass unix:/tmp/_var_wwwdjango_mywebsite.socket;
                     include /etc/nginx/fastcgi_params;
             }
    }

here is my fastcgi_params file :

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   PATH_INFO               $fastcgi_script_name;
fastcgi_param   SCRIPT_FILENAME         $request_filename;
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  HTTPS                   $server_https;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param   REDIRECT_STATUS         200;

remark :

  • if I add url(r'^$', 'myapp.views.index') to my pattern it render me the view for all my requests... so it's clearly a nginx conf or fast_cgi problem.

  • When I execute my website with the django development server my url are ok.


回答1:


You are missing the PATH_INFO parameter.

fastcgi_param PATH_INFO $fastcgi_script_name;

See the nginx docs: http://wiki.nginx.org/DjangoFastCGI

If you try "nginx PATH_INFO django" in your favourite search engine, it looks like some users had to remove the SCRIPT_NAME parameter as well to get it to work.



来源:https://stackoverflow.com/questions/9298335/empty-current-url-for-django-deployed-with-nginx-and-fastcgi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!