Advertise the onion site on clearnet via Onion-Location header.

This commit is contained in:
2026-09-11 15:26:03 +02:00
parent 08a0bdcdb8
commit 77cd686347
4 changed files with 26 additions and 0 deletions
+1
View File
@@ -19,6 +19,7 @@ NODE_ENV=development
CORS_ORIGINS=http://localhost:5173,http://127.0.0.1:5173 CORS_ORIGINS=http://localhost:5173,http://127.0.0.1:5173
CLEARNET_DOMAIN=localhost CLEARNET_DOMAIN=localhost
ONION_HOSTNAME=samplexxxxxxxxx.onion
JWT_SECRET=change-me-in-production JWT_SECRET=change-me-in-production
JWT_EXPIRES_IN_MS=604800000 # 7 days JWT_EXPIRES_IN_MS=604800000 # 7 days
+8
View File
@@ -144,6 +144,14 @@ Save and exit the editor. Optional — run once manually to verify:
./deploy/scripts/show-onion.sh ./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 ## 9. Complete shop setup
1. Open the CMS on clearnet or onion (`/cms`). 1. Open the CMS on clearnet or onion (`/cms`).
+2
View File
@@ -18,5 +18,7 @@ server {
ssl_certificate /etc/nginx/certs/live/${CLEARNET_DOMAIN}/fullchain.pem; ssl_certificate /etc/nginx/certs/live/${CLEARNET_DOMAIN}/fullchain.pem;
ssl_certificate_key /etc/nginx/certs/live/${CLEARNET_DOMAIN}/privkey.pem; ssl_certificate_key /etc/nginx/certs/live/${CLEARNET_DOMAIN}/privkey.pem;
${ONION_LOCATION_HEADER}
include /etc/nginx/snippets/nullcart-locations-${SHOP_SURFACE}.conf; include /etc/nginx/snippets/nullcart-locations-${SHOP_SURFACE}.conf;
} }
+15
View File
@@ -16,6 +16,21 @@ render_server() {
surface="$3" surface="$3"
SHOP_SURFACE="$surface" SHOP_SURFACE="$surface"
export SHOP_SURFACE CLEARNET_DOMAIN BACKEND_PORT 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}' \ envsubst '${CLEARNET_DOMAIN} ${BACKEND_PORT} ${SHOP_SURFACE}' \
< "$template_path" \ < "$template_path" \
> "$output_path" > "$output_path"