An open API service indexing awesome lists of open source software.

https://github.com/caged/nginx-test

example on how to serve nextjs subdirectories using a subdomain and nginx reverse proxy
https://github.com/caged/nginx-test

Last synced: about 2 months ago
JSON representation

example on how to serve nextjs subdirectories using a subdomain and nginx reverse proxy

Awesome Lists containing this project

README

          

### Running

Edit your `/etc/hosts` file and add

```
127.0.0.1 nginx-test.local
127.0.0.1 admin.nginx-test.local
```

```
docker-compose up
```

### About

How to use an nginx reverse proxy to serve a subdirectory in nextjs through a subdomain. For example, if you have a pages directory that is structured

```
pages/
- index.js
- about.js
- admin/
- index.js
- dashboard.js
```

Typically, you would access the admin pages as `http://host/admin` and `http://host/admin/dashboard`, however if you use nginx reverse proxy, you can use a subdomain to mask the `admin` folder.

- http://admin.host - serves pages/admin
- http://admin.host/dashboard - serves pages/admin/dashboard

It's important to note that you must set the `assetPrefix` in `next.config.js` to the host root when doing this.