server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html =404;
}
}
The try_files
directive tries the $uri
first, then $uri/
, then /index.html
which should exist. In case all fails, it will use =404
to serve the default 404 page.