Django + NGINX URL问题 [英] Django + NGINX URL Problem

查看:180
本文介绍了Django + NGINX URL问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了Django的FastCGI + NGINX,但是它仅适用于根URL:对http://example.com/anything的任何请求都将重定向到http://example.com. Django的内部服务器工作正常,NGINX静态文件服务以及根URL的FastCGI处理都很好,错误日志也很清楚.这是我的配置的服务器部分:

I have set up Django's FastCGI + NGINX, but it's only working for root url: any request to http://example.com/anything redirects to http://example.com. Django's internal server working fine, NGINX static file serving and FastCGI processing of the root URL is fine, error log is clear. Here is my config's server section:

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

我做错了什么?预先感谢.

What am I doing wrong? Thanks in advance.

推荐答案

尝试以下配置:

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.

Make sure you've already informed nginx the port which django runs.

这篇关于Django + NGINX URL问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆