Generate Nginx routing configuration for static Next.js projects.
npm install nx-nginx-routesjson
{
"page": "/[foo]",
"regex": "^/([^/]+?)(?:/)?$",
"routeKeys": { "foo": "foo" },
"namedRegex": "^/(?[^/]+?)(?:/)?$"
}
`
... into Nginx routes like:
`nginx
location ~ ^/([^/]+?)(?:/)?$ {
try_files /[foo].html /index.html;
}
`
Getting started
$3
`shell
yarn add --dev next-nginx-routes
`
$3
Add next-nginx-routes to your export script:
`json
{
"export": "next build && next export && next-nginx-routes"
}
`
And run Next.js export:
`shell
yarn run export
`
$3
Finally include the generated configuration file next-routes.conf and the Next.js output in your Nginx site configuration file.
Requirements
- Next.js 12 or higher
- Node.js 14 or higher
More
- See example` folder for a minimal Docker example.