Django + NGINX URL Problem

2019-06-03 19:47发布

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.

标签: django url nginx
2条回答
Bombasti
2楼-- · 2019-06-03 20:34

Try this configs:

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

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

查看更多
我想做一个坏孩纸
3楼-- · 2019-06-03 20:38

You may need to add this line to location /:

fastcgi_split_path_info ^()(.*)$;

from djangoandnginx

查看更多
登录 后发表回答