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
- Host: GitHub
- URL: https://github.com/caged/nginx-test
- Owner: caged
- Created: 2020-01-10T03:53:30.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-10T06:41:12.000Z (over 6 years ago)
- Last Synced: 2025-03-13T15:19:14.748Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 101 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
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.