try_files 403我用这样的Nginx配置为域:Django和Nginx的站点根页面
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配置:
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/somepage.htm所有URL的作品好,除了http://domain.com/它总是由Nginx显示403。
如果添加静态index.htm文件到网站根 - 它打开,因为try_files的指令
如果你没有静态的index.htm,但拨打http://domain.com/index.htm页由Django的
打开它BUF你没有静态index.htm,并打开http://domain.com/你没有页面,但想法 index.htm应该被查看并传递给django作为try_files链中的最后一个。
如何在这种情况下使http://domain.com/工作(应该调用django的index.htm)?
谢谢。据我所知,我以某种方式解决了这个问题,并采用了不同的方法。 – Zelid 2010-09-15 10:25:24