How Can I Configure nginx to Use Pretty URLs for Static Sites?
You should use try_files for this. The idea is that you will create your URLs without .html and Nginx will silently add it. Example config below.
server {
#listen/server_name/root here.
try_files $uri.html $uri $uri/ @notfound;
location @notfound {
alias /your/404/file.html
return 404;
}
}
Use static location:
location / {
index index.html;
root /var/www/nginx-default;
}
location /api {
index api.html;
alias /var/www/nginx-default;
}
location /quickstart {
index quickstart.html;
alias /var/www/nginx-default;
}
regexp:
location ~/(.*)$ {
alias /var/www/nginx-default/$1.html;
}