Django+;NGINX URL问题
我已经设置了Django的FastCGI+NGINX,但它只对根url有效:任何对Django+;NGINX URL问题,django,url,nginx,Django,Url,Nginx,我已经设置了Django的FastCGI+NGINX,但它只对根url有效:任何对http://example.com/anything重定向到http://example.com。Django的内部服务器工作正常,NGINX静态文件服务和根URL的FastCGI处理正常,错误日志清晰。以下是我的配置的服务器部分: server { listen 80; server_name example.com; location / {
http://example.com/anything
重定向到http://example.com
。Django的内部服务器工作正常,NGINX静态文件服务和根URL的FastCGI处理正常,错误日志清晰。以下是我的配置的服务器部分:
server {
listen 80;
server_name example.com;
location / {
fastcgi_pass localhost:8000;
include fastcgi_params;
}
location /static/ {
alias /root/web_development/src/web_development/static/;
}
}
我做错了什么?提前感谢。尝试以下配置:
server {
listen 80;
server_name example.com;
location / {
root /home/example.com/foo;
fastcgi_pass 127.0.0.1:8000;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
}
}
确保您已将django运行的端口通知nginx。尝试以下配置:
server {
listen 80;
server_name example.com;
location / {
root /home/example.com/foo;
fastcgi_pass 127.0.0.1:8000;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
}
}
确保您已将django运行的端口通知nginx。您可能需要将此行添加到位置/:
fastcgi_split_path_info ^()(.*)$;
从中,您可能需要将此行添加到位置/:
fastcgi_split_path_info ^()(.*)$;
fromfastcgi_参数的内容是什么?fastcgi_参数的内容是什么?它肯定在工作!非常感谢。问题在于
fastcgi\u params
中缺少PATH\u INFO
参数。此设置不是通过fastcgi传递所有文件吗?在我看来,只有php文件应该被匹配,而其他资源应该被直接提供。这肯定是有效的!非常感谢。问题在于fastcgi\u params
中缺少PATH\u INFO
参数。此设置不是通过fastcgi传递所有文件吗?在我看来,应该只匹配php文件,而直接提供其他资源。