Django and Nginx try_files 403 for site root page
I am using this Nginx configuration for a 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 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"),
}
all urls like http://domain.com/somepage.htm work well except http://domain.com/ it always shows 403 by Nginx.
if you add a static index.htm file to the site root - it opens because of the try_files directive
if you don't have static index.htm but call http://domain.com/index.htm the page opens django
buf you don't have a static index.htm and open http://domain.com/ you don't have a page, but in theory index.htm should be viewed and passed to django as the last in the try_files chain.
how to make http://domain.com/ work (should call django index.htm) in this case?
+2
source to share
2 answers