【问题标题】:Django + NGINX URL ProblemDjango + NGINX URL 问题
【发布时间】:2011-01-07 11:08:15
【问题描述】:

我已经设置了 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/;
        }
}

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

【问题讨论】:

  • fastcgi_params的内容是什么?

标签: django url nginx


【解决方案1】:

试试这个配置:

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 运行的端口。

【讨论】:

  • 它确实有效!谢谢!问题在于fastcgi_params 中没有PATH_INFO 参数。
  • 这个设置不是通过fastcgi传递所有文件吗?在我看来,应该只匹配 php 文件,而应该直接提供其他资源。
【解决方案2】:

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

fastcgi_split_path_info ^()(.*)$;

来自djangoandnginx

【讨论】:

    猜你喜欢
    • 2015-11-08
    • 1970-01-01
    • 1970-01-01
    • 2019-06-07
    • 2015-12-17
    • 2019-03-19
    • 2011-01-15
    • 2016-12-11
    • 1970-01-01
    相关资源
    最近更新 更多