问题描述
当我查询此网址
http://mywebsite.com/foos/
Django给我:
Page not found (404)
Request Method: GET
Request URL: http://mywebsite.com/foos//
The current URL, , didn't match any of these.
错误:
- 请求URL中添加我'/'结束,
- 在当前的URL是空的。
the errors :
- in Request URL it add me '/' at the end,
- in current URL is empty.
我的规格:
我运行我的django网站与nginx作为对于fast_cgi来说,reverseeproxy。
my spec :
I run my django website with nginx as reverseproxy to the fast_cgi.
这里我的网站conf为nginx:
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;
}
}
这是我的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;
备注:
-
如果我向我的模式添加
url(r'^ $','myapp.views.index')
,它会使我看到我所有的请求...所以这显然是一个nginx conf或fast_cgi的问题。
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.
当我使用django开发服务器执行我的网站时,我的url可以。
When I execute my website with the django development server my url are ok.
推荐答案
您缺少PATH_INFO参数。
You are missing the PATH_INFO parameter.
fastcgi_param PATH_INFO $fastcgi_script_name;
请参阅nginx文档:
See the nginx docs: http://wiki.nginx.org/DjangoFastCGI
如果您在自己喜欢的搜索引擎中尝试nginx PATH_INFO django ,似乎有些用户也必须删除SCRIPT_NAME参数,以使其正常工作。
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.
这篇关于为Nginx和fastcgi部署的Django空“当前url”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!