diff --git a/.env.example b/.env.example index 496693b..c7035bf 100644 --- a/.env.example +++ b/.env.example @@ -19,6 +19,7 @@ NODE_ENV=development CORS_ORIGINS=http://localhost:5173,http://127.0.0.1:5173 CLEARNET_DOMAIN=localhost +ONION_HOSTNAME=samplexxxxxxxxx.onion JWT_SECRET=change-me-in-production JWT_EXPIRES_IN_MS=604800000 # 7 days diff --git a/deploy/DEPLOYMENT_GUIDE.md b/deploy/DEPLOYMENT_GUIDE.md index ffcd5a1..91b03db 100644 --- a/deploy/DEPLOYMENT_GUIDE.md +++ b/deploy/DEPLOYMENT_GUIDE.md @@ -144,6 +144,14 @@ Save and exit the editor. Optional — run once manually to verify: ./deploy/scripts/show-onion.sh ``` +Copy the hostname into `.env.prod` as `ONION_HOSTNAME`, then recreate nginx: + +```bash +docker compose --env-file .env.prod -f docker-compose.prod.yml up -d --force-recreate nginx +``` + +Tor Browser will then show ".onion available" when visitors open the clearnet site over HTTPS. + ## 9. Complete shop setup 1. Open the CMS on clearnet or onion (`/cms`). diff --git a/nginx/conf.d/clearnet.conf.template b/nginx/conf.d/clearnet.conf.template index 39b04ee..b5586c4 100644 --- a/nginx/conf.d/clearnet.conf.template +++ b/nginx/conf.d/clearnet.conf.template @@ -18,5 +18,7 @@ server { ssl_certificate /etc/nginx/certs/live/${CLEARNET_DOMAIN}/fullchain.pem; ssl_certificate_key /etc/nginx/certs/live/${CLEARNET_DOMAIN}/privkey.pem; + ${ONION_LOCATION_HEADER} + include /etc/nginx/snippets/nullcart-locations-${SHOP_SURFACE}.conf; } diff --git a/nginx/docker-entrypoint.sh b/nginx/docker-entrypoint.sh index 3308e23..a1d214c 100755 --- a/nginx/docker-entrypoint.sh +++ b/nginx/docker-entrypoint.sh @@ -16,6 +16,21 @@ render_server() { surface="$3" SHOP_SURFACE="$surface" export SHOP_SURFACE CLEARNET_DOMAIN BACKEND_PORT + + if [ "$surface" = "clearnet" ]; then + if [ -n "${ONION_HOSTNAME:-}" ]; then + export ONION_LOCATION_HEADER="add_header Onion-Location \"http://${ONION_HOSTNAME}\$request_uri\";" + else + export ONION_LOCATION_HEADER="" + fi + + envsubst '${CLEARNET_DOMAIN} ${BACKEND_PORT} ${SHOP_SURFACE} ${ONION_LOCATION_HEADER}' \ + < "$template_path" \ + > "$output_path" + + return + fi + envsubst '${CLEARNET_DOMAIN} ${BACKEND_PORT} ${SHOP_SURFACE}' \ < "$template_path" \ > "$output_path"