Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django+;NGINX URL问题_Django_Url_Nginx - Fatal编程技术网

Django+;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 / {

我已经设置了Django的FastCGI+NGINX,但它只对根url有效:任何对
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 ^()(.*)$;

from

fastcgi_参数的内容是什么?fastcgi_参数的内容是什么?它肯定在工作!非常感谢。问题在于
fastcgi\u params
中缺少
PATH\u INFO
参数。此设置不是通过fastcgi传递所有文件吗?在我看来,只有php文件应该被匹配,而其他资源应该被直接提供。这肯定是有效的!非常感谢。问题在于
fastcgi\u params
中缺少
PATH\u INFO
参数。此设置不是通过fastcgi传递所有文件吗?在我看来,应该只匹配php文件,而直接提供其他资源。