我用这样的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"),
}
像所有的URL http://domain.com/somepage.htm做工不错,除了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)在这种情况下?