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