Заработало вот с таким конфигом:
server {
listen 80;
server_name _;
root /home/user/www/example.com/public_html;
index index.html;
# example.com/foo// => example.com/foo/
if ($request_uri ~ "^[^?]*?//") {
rewrite "^" $scheme://$host$uri permanent;
}
# example.com/index.html => example.com/
rewrite (?i)^(.*)index\.html$ $1/ permanent;
# example.com/foo => example.com/foo/
rewrite ^([^.]*[^/])$ $1/ permanent;
# example.com/foo.html => example.com/foo/
rewrite (?i)^(.*)/(.*)\.html $1/$2/ permanent;
# prevent access from example.com/index/
location ~ /index/ {
return 404;
}
location / {
# remove slash from url end for access .html files
# example.com/foo/ => example.com/foo
rewrite ^/(.*)/$ /$1 last;
try_files $uri.html $uri $uri/index.html $uri/ =404;
}
}