# next-nginx-routes

> Generate Nginx routing configuration for static Next.js projects.

Latest version **1.3.0** (published 2024-10-22) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install next-nginx-routes
pnpm add next-nginx-routes
yarn add next-nginx-routes
bun add next-nginx-routes
```

Provides the command `next-nginx-routes`.

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2024-10-22 |
| First published | 2022-03-28 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 31 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 161 |
| Maintainers | friedjoff |
| Keywords | export, Next.js, Nginx, configuration, routing, static |

## Links

- npm: https://www.npmjs.com/package/next-nginx-routes
- Repository: https://github.com/geops/next-nginx-routes
- Homepage: https://geops.com/en/blog/next-nginx-routes
- Issues: https://github.com/geops/next-nginx-routes/issues
- npm.io page: https://npm.io/package/next-nginx-routes

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.3.0 (latest) — 2024-10-22
- 1.2.1 — 2023-11-03
- 1.2.0 — 2023-11-03
- 1.1.1 — 2022-10-28
- 1.1.0 — 2022-09-29
- 1.0.0 — 2022-03-28

## README

# next-nginx-routes

Generate Nginx routes configuration file for Next.js static HMTL export, also known as `output: export`.

This dependency-free [NPM package](https://www.npmjs.com/package/next-nginx-routes) provides a NPM script to convert all your Next.js routes like:

```json
{
  "page": "/[foo]",
  "regex": "^/([^/]+?)(?:/)?$",
  "routeKeys": { "foo": "foo" },
  "namedRegex": "^/(?<foo>[^/]+?)(?:/)?$"
}
```

... into Nginx routes like:

```nginx
location ~ ^/([^/]+?)(?:/)?$ {
  try_files /[foo].html /index.html;
}
```

Note: currently only Next.js pages router is fully supported.

## Getting started

### Installation

```shell
yarn add --dev next-nginx-routes
```

Make sure [`output: "export"`](https://nextjs.org/docs/pages/building-your-application/deploying/static-exports#configuration) is configured in your `next.config.js` file.

### Generate Nginx configuration file

Add next-nginx-routes to your build script:

```json
{
  "build": "next build && next-nginx-routes"
}
```

And run Next.js export:

```shell
yarn run build
```

### Include Nginx configuration file

Finally include the generated configuration file `next-routes.conf` in your Nginx site configuration file and make the Next.js `out` directory available to Nginx.

## Requirements

- [Next.js](https://nextjs.org) 12 or higher
- [Node.js](https://nodejs.org) 18 or higher

## More

- See [`example`](https://github.com/geops/next-nginx-routes/tree/main/example) folder for a minimal Docker example.
- Read more about this approach in our [blog post](https://geops.ch/en/blog/next-nginx-routes).

---
_Source: https://npm.io/package/next-nginx-routes · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
