Next.js supports Static Exports.
However, it's a lot of work to manage the routing for the generated file without Vercel. Dynamic Routes feature makes routing more difficult.
This application automatically generates nginx rewrite rules for generated files.
- Next.js (Pages Router only)
- nginx
npm install -D @progfay/nextjs-ssg-rewrite-rule-gen
Note
This application is available with zero configuration.
You can run this application with config in following command: nextjs-ssg-rewrite-rule-gen --config config.json
{
"pagesDirPath": "apps/src/pages",
"ignoreRoutes": ["/debug"],
"nginxConfigs": [
{
"pattern": "^/credential$",
"directives": ["add_header Cache-Control \"no-store\";"]
}
],
"basePath": "/app",
"trailingSlash": true
}
Available configs:
pagesDirPath
: customize path forpages
directoryignoreRoutes
: exclude specific paths from outputsnginxConfigs
: customize configuration inside of nginxlocation
directivepattern
: pattern string ofRegExp
directives
: additional nginx directives
basePath
: next.config.js Options: basePath | Next.jstrailingSlash
: next.config.js Options: trailingSlash | Next.js
pages
directory:
pages
└── user
├── [id]
└── index.js
└── new
└── index.js
↓
Generated files with Static Exports (next build
and output: "export"
):
out
└── user
├── [id].html
└── new.html
↓
nginx rewrite rules (generated by @progfay/nextjs-ssg-rewrite-rule-gen
):
location ~ ^/user/new/?$ {
rewrite ^/user/new/?$ /user/new.html break;
}
location ~ ^/user/[^/]+?/?$ {
rewrite ^/user/[^/]+?/?$ /user/[id].html break;
}