Prepare NuxtJS for static deployment

### In order to deploy Nuxt as a static website you need to:

1. Upgrade nuxt to 2.14.0
2. Set `target: 'static'` in your `nuxt.config.js`
3. Set fallback 404 page:`generate: { fallback: '404.html' }`
4. Run nuxt generate

### You then need to tell Nginx to properly handle slashes for subpages:

```bash

    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;
    }

```

Zeno Popovici
13 May 2021
« Back to post