Django + NGINX URL问题

时间:2010-01-20 20:32:14

标签: django url nginx

我已经设置了Django的FastCGI + NGINX,但它只适用于root 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/;
        }
}

我做错了什么?提前谢谢。

2 个答案:

答案 0 :(得分:4)

试试这个配置:

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;
        }
}

确保你已经告知nginx django运行的端口。

答案 1 :(得分:2)

您可能需要将此行添加到位置/:

fastcgi_split_path_info ^()(.*)$;

来自djangoandnginx