Migrate Your Local Dev Instance to TLS/HTTPS
Part 2 โ Migrate your Local Dev to HTTPS (TLS)
This section guides you through configuring your local development setup to use HTTPS (TLS) for both SoVisu+ and Keycloak. This is required to enable Saml2 authentication.
๐ฏ Goal
Run SoVisu+ on https://sovisuplus.local:3000 and Keycloak on https://keycloak.local:8443, ensuring your local machine and applications trust the self-signed certificates.
๐ Step 2: Configure Environment Variables
You need to update several environment variables in your Next.js applicationโs .env file and the Keycloak Docker configuration.
A. SoVisu+ (sovisuplus/.env)
Update the URLs to reflect the new https scheme and the Keycloak HTTPS port (8443).
# Before (HTTP)
WS_SCHEME=ws
# KEYCLOAK_ISSUER="[http://keycloak.local:8080/realms/crisalid-inst](http://keycloak.local:8080/realms/crisalid-inst)"
# KEYCLOAK_PUBLIC_URL="[http://keycloak.local:8080/realms/crisalid-inst](http://keycloak.local:8080/realms/crisalid-inst)"
# NEXTAUTH_URL="[http://sovisuplus.local:3000/api/auth](http://sovisuplus.local:3000/api/auth)"
# After (HTTPS)
WS_SCHEME=wss
KEYCLOAK_ISSUER="[https://keycloak.local:8443/realms/crisalid-inst](https://keycloak.local:8443/realms/crisalid-inst)"
KEYCLOAK_PUBLIC_URL="[https://keycloak.local:8443/realms/crisalid-inst](https://keycloak.local:8443/realms/crisalid-inst)"
NEXTAUTH_URL="[https://sovisuplus.local:3000/api/auth](https://sovisuplus.local:3000/api/auth)"
# UNCOMMENT THIS LINE to allow the Next.js server (Node.js) to communicate
# with Keycloak without complaining about the self-signed certificate.
NODE_TLS_REJECT_UNAUTHORIZED=0B. Docker Config (crisalid-deployment/docker/.env)
Update the scheme and port for both Keycloak and SoVisu+ to use HTTPS.
# Before
# KEYCLOAK_SCHEME=http
# KEYCLOAK_PORT=8080
# SOVISUPLUS_SCHEME=http
# After
KEYCLOAK_SCHEME=https
KEYCLOAK_PORT=8443
SOVISUPLUS_SCHEME=httpsC. Docker Keycloak Config (docker/keycloak/.env)
Ensure the hostname enforcement variables are set correctly for the TLS setup.
# Invert these values from the default/sample:
KEYCLOAK_HTTP_ENABLED=false
KEYCLOAK_HOSTNAME_STRICT_HTTPS=true๐ ๏ธ Step 3: Run Next.js Dev Server with HTTPS
To run the Next.js development server over HTTPS, we need to use the --experimental-https flag along with the certificate files you generated. This is done via a dedicated script in package.json.
- package.json contains a โdev-tlsโ script:
"scripts": {
"dev": "next dev -H sovisuplus.local -p 3000",
"dev-tls": "next dev --experimental-https --experimental-https-key ~/local-certs/sovisuplus.local+4-key.pem --experimental-https-cert ~/local-certs/sovisuplus.local+4.pem -H sovisuplus.local -p 3000"
}- How ro Run the Dev Server with TLS:
Instead of npm run dev, use:
npm run dev-tlsReference: This approach uses built-in Next.js functionality. See Vercel KB: Access Next.js localhost HTTPS certificate self-signed.
๐ณ Step 4: Configure and Restart Keycloak (TLS Profile)
You must now modify your docker compose environment to start Keycloak with its HTTPS configuration, which is handled via a dedicated keycloak-tls profile.
- Destroy the Old DB:
Keycloak will write the old HTTP configuration into its database. Itโs safest to destroy the database volume to force a clean, HTTPS-based configuration import.
# Ensure Docker compose is stopped
# Remove the persisted DB volume
sudo rm -rf docker/keycloak/postgres-data- Renew Configuration Script:
Re-run your configuration script to ensure the Keycloak realm file (crisalid-inst.json) contains the new https:// URLs.
Ensure all the environment variables are set correctly before running the script (step 2).
./configure_keycloak.sh- Launch Docker Compose with the TLS Profile:
Replace --profile keycloak with the dedicated --profile keycloak-tls when starting Docker Compose.
docker compose \
# ... all other profiles ...
--profile keycloak-tls \
--profile sovisuplus-db \
up --remove-orphansVerification
- Keycloak: Should be accessible securely at
https://keycloak.local:844. - SoVisu+: Should be accessible securely at
https://sovisuplus.local:3000.