站点根页面的Django和Nginx try_files 403 [英] Django and Nginx try_files 403 for site root page

查看:107
本文介绍了站点根页面的Django和Nginx try_files 403的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在域中使用这样的Nginx配置:

I use such Nginx configuration for the domain:

server_name_in_redirect off; 
listen 80;
server_name  ~^(www\.)?(.+)$;
root /var/www/$2/htdocs;

location / {
    try_files  $uri  $uri/ $uri/index.htm  @django;
    index index.html index.htm;
}

location @django {
    fastcgi_pass 127.0.0.1:8801;
    fastcgi_param PATH_INFO $fastcgi_script_name;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param QUERY_STRING $query_string;
    fastcgi_param SERVER_NAME $server_name;
    fastcgi_param SERVER_PORT $server_port;
    fastcgi_param SERVER_PROTOCOL $server_protocol;
    fastcgi_param CONTENT_TYPE $content_type;
    fastcgi_param CONTENT_LENGTH $content_length;
    fastcgi_pass_header Authorization;
    fastcgi_intercept_errors off;
    fastcgi_param REMOTE_ADDR $remote_addr;
}

Django URL配置:

Django URL config:

urlpatterns = patterns('',   
    url(r'^$', home, name='home'),
    url(r'index.htm', home, name='home'),    
    url(r'^(?P<name>.*).htm$', plain_page, name="plain_page"),
}

http://domain.com/始终显示Nginx的403.

all urls like http://domain.com/somepage.htm works good, except http://domain.com/ it always shows 403 by Nginx.

如果将静态index.htm文件添加到站点根目录-由于try_files指令而将其打开

if you add static index.htm file to the site root - it's opened because of try_files directive

如果您没有静态index.htm,请致电 http://domain.com/index.htm 页面由django打开

if you have no static index.htm, but call http://domain.com/index.htm page is opened by django

在没有静态index.htm的情况下,打开 http://domain.com/,您将没有页面,但根据想法 应该查找index.htm并将其作为try_files链中的最后一个传递给django.

buf it you have no static index.htm and open http://domain.com/ you get no page, but by idea index.htm should be looked and passed to the django as the last in the try_files chain.

在此如何使 http://domain.com/工作(应称为django的index.htm)案子?

how to make http://domain.com/ work (should call django's index.htm) in this case?

推荐答案

添加此

location = / { rewrite ^(.*)$ /index.htm last; }

location = / { rewrite ^(.*)$ /index.htm last; }

root行下面进行URI的重写,然后再进行进一步处理.

underneath the root line to do a rewrite of the URI before further processing.

PS.自您提出要求以来,您可能已在这一年中进行了整理,但其他人可以在这里查看.

PS. You have probably sorted this out during the year since your asked, but here it is for other to see.

这篇关于站点根页面的Django和Nginx try_files 403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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