next-nginx-routes
Generate Nginx routes configuration file for Next.js static HMTL export.
This NPM package allows you to convert Next.js routes like:
{
"page": "/[foo]",
"regex": "^/([^/]+?)(?:/)?$",
"routeKeys": { "foo": "foo" },
"namedRegex": "^/(?<foo>[^/]+?)(?:/)?$"
}
... into Nginx routes like:
location ~ ^/([^/]+?)(?:/)?$ {
try_files /[foo].html /index.html;
}
Getting started
Installation
yarn add --dev next-nginx-routes
Generate Nginx configuration file
Add next-nginx-routes to your export script:
{
"export": "next build && next export && next-nginx-routes"
}
And run Next.js export:
yarn run export
Include Nginx configuration file
Finally include the generated configuration file next-routes.conf
and the Next.js output in your Nginx site configuration file.