Two objectives:
(1) When /page.html is entered, we want Nginx to redirect to /page. This can be done by:
location / {
if ($request_uri ~ ^/(.*)\.html$) {
return 302 /$1;
}
}(2) When a link /page is clicked, we want Nginx to serve static page named "page.html" in your www directory.
location / {
try_files $uri $uri.html $uri/ =404;
}(3) Combine both of these, you get the following location block:
location / {
if ($request_uri ~ ^/(.*)\.html$) {
return 302 /$1;
}
try_files $uri $uri.html $uri/ =404;
}(4) Reload Nginx
sudo service nginx restart