This repository serves as a guide and configuration setup for integrating Traefik with a Next.js application WITHOUT docker. The goal is to implement Traefik as a reverse proxy and load balancer, providing a customized host, such as "nextjs.localhost." Additionally, the setup includes TLS integration for secure HTTPS access, utilizing a certificate generated by mkcert.
Before getting started, ensure you have the following prerequisites installed on your system:
- Traefik
- Mkcert
Follow these steps to integrate Traefik with your Next.js app:
-
Clone this repository:
git clone https://github.com/Clement-Muth/nextjs-traefik.git
-
Navigate to the project directory:
cd nextjs-traefik
-
Generate SSL certificates using mkcert:
mkcert -uninstall sudo rm -rf /etc/ssl/certs/mkcert* mkdir -p certs/root mkcert -cert-file certs/cert.pem -key-file certs/key.pem "nextjs.localhost" mkcert -install
-
Update Traefik configuration in the
traefik/dynamic.yaml
file as needed. -
Run traefik:
traefik --configFile=traefik/traefik.yaml
-
Access the Next.js app using the configured host:
https://nextjs.localhost
Adjust the Traefik configuration based on your requirements. This file includes settings for entry points, middleware, and SSL certificates.
Feel free to contribute to this project by opening issues or submitting pull requests. Your feedback and enhancements are highly appreciated!
This project is licensed under the MIT License.