In order to deploy Nuxt as a static website you need to:
- Upgrade nuxt to 2.14.0
- Set
target: 'static'
in your nuxt.config.js
- Set fallback 404 page:
generate: { fallback: '404.html' }
- Run nuxt generate
You then need to tell Nginx to properly handle slashes for subpages:
location /.
{
# Remove trailing slash and redirect it
rewrite ^(.+)/+$ $1 permanent;
# Redirect index.html
rewrite ^(.+)/index.html$ $1 permanent;
# Serve folder path via index.html
try_files $uri $uri/index.html =404;
# Serve a custom static error page
error_page 404 /404.html;
}