Nginx:请求文件没有扩展名

如何在没有扩展名的情况下在nginx服务器上请求html页面?

即:example.com/about应该返回example.com/about.html。 这应该是所有的HTML页面。

我有以下几点:

try_files $uri $uri.html; index index.html; 

哪些工作,但访问example.com/导致403禁止:

 2015/01/20 19:26:11 [error] 32618#0: *373061 access forbidden by rule 

并访问一个不存在的页面(example.com/bla)导致redirect循环:

 2015/01/20 19:26:57 [error] 32620#0: *373065 rewrite or internal redirection cycle while internally redirecting to "/bla.html.html.html.html.html.html.html.html.html.html.html" 

更新完整的nginxconfiguration:

 server { listen [::]:80; server_name example.com; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; root /var/www/example/; try_files $uri $uri.html /index.html =404; index index.html; expires max; autoindex off; # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } } 

修改你的try_files行如下所示:

 try_files $uri $uri.html /index.html =404; 

你看到一个循环的原因是,如果在search过程中没有find有效的位置,try_files将强制redirect到最后一个条目。

进一步阅读和参考: http : //wiki.nginx.org/HttpCoreModule#try_files