清空“当前网址”用于使用 Nginx 和 fastcgi 部署的 Django
当我查询这个 url
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 为空。
我的规格:
我使用 nginx 作为 fast_cgi 的反向代理来运行我的 django 网站。
这是我的 nginx 网站配置:
server {
listen 80;
server_name mywebsite.com;
location / {
fastcgi_pass unix:/tmp/_var_wwwdjango_mywebsite.socket;
include /etc/nginx/fastcgi_params;
}
}
这是我的 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 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 问题。当我使用 django 开发服务器执行我的网站时,我的 url 没问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您缺少 PATH_INFO 参数。
请参阅 nginx 文档: http://wiki.nginx.org/DjangoFastCGI
如果您尝试“nginx PATH_INFO django ” 在您最喜欢的搜索引擎中,看起来有些用户还必须删除 SCRIPT_NAME 参数才能使其正常工作。
You are missing the PATH_INFO parameter.
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.