Skip to content

Commit fd54a32

Browse files
authored
Allow to configure ports #5
2 parents 6a206e5 + 6d1a057 commit fd54a32

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
DOMAIN=local.example.com
2+
HTTP_PORT=8080
3+
HTTPS_PORT=8443
24
UPSTREAM_URL=http://host.docker.internal:3000

.github/workflows/test.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88

99
env:
1010
DOMAIN: sslproxy.stackpop.com
11+
HTTP_PORT: 9080
12+
HTTPS_PORT: 9443
13+
UPSTREAM_URL: http://host.docker.internal:3000
1114

1215
jobs:
1316
test:
@@ -24,7 +27,9 @@ jobs:
2427
- name: Create .env
2528
run: |
2629
echo "DOMAIN=${{ env.DOMAIN }}" > .env
27-
echo "UPSTREAM_URL=http://host.docker.internal:3000" >> .env
30+
echo "HTTP_PORT=${{ env.HTTP_PORT }}" >> .env
31+
echo "HTTPS_PORT=${{ env.HTTPS_PORT }}" >> .env
32+
echo "UPSTREAM_URL=${{ env.UPSTREAM_URL }}" >> .env
2833
2934
- name: Add test domain to hosts
3035
run: echo "127.0.0.1 ${{ env.DOMAIN }}" | sudo tee -a /etc/hosts
@@ -52,12 +57,11 @@ jobs:
5257

5358
- name: Test HTTP redirect
5459
run: |
55-
curl -s -o /dev/null -w "%{http_code}" http://${{ env.DOMAIN }}:8080 | grep -q "301\|308"
60+
curl -s -o /dev/null -w "%{http_code}" http://${{ env.DOMAIN }}:${{ env.HTTP_PORT }} | grep -q "301\|308"
5661
5762
- name: Test HTTPS proxies to upstream
5863
run: |
59-
curl -s --cacert certs/${{ env.DOMAIN }}.rootCA.pem https://${{ env.DOMAIN }}:8443 | grep -q "nginx"
60-
64+
curl -s --cacert certs/${{ env.DOMAIN }}.rootCA.pem https://${{ env.DOMAIN }}:${{ env.HTTPS_PORT }} | grep -q "nginx"
6165
- name: Show logs on failure
6266
if: failure()
6367
run: docker compose logs

CLAUDE.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Environment variables (set in `.env`):
4040

4141
- `DOMAIN` - Domain name for SSL cert (default: `localhost`)
4242
- `UPSTREAM_URL` - URL for your local app (default: `http://host.docker.internal:3000`)
43+
- `HTTP_PORT` - HTTP port for redirects (default: `8080`)
44+
- `HTTPS_PORT` - HTTPS port for proxy (default: `8443`)
4345

4446
## Files
4547

@@ -51,5 +53,5 @@ Environment variables (set in `.env`):
5153

5254
## Ports
5355

54-
- `8080` → HTTP (redirects to HTTPS on 8443)
55-
- `8443` → HTTPS (proxies to `${UPSTREAM_URL}`)
56+
- `${HTTP_PORT}` (default `8080`) → HTTP (redirects to HTTPS)
57+
- `${HTTPS_PORT}` (default `8443`) → HTTPS (proxies to `${UPSTREAM_URL}`)

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,14 @@ Note (Linux): Requires Docker Engine 20.10+ for `host-gateway` support.
101101
| Variable | Default | Description |
102102
| -------------- | ---------------------------------- | ---------------------- |
103103
| `DOMAIN` | `localhost` | Domain for SSL cert |
104+
| `HTTP_PORT` | `8080` | HTTP port (redirects) |
105+
| `HTTPS_PORT` | `8443` | HTTPS port (proxy) |
104106
| `UPSTREAM_URL` | `http://host.docker.internal:3000` | URL for your local app |
105107

106108
## Ports
107109

108-
- `8080` - HTTP (redirects to HTTPS)
109-
- `8443` - HTTPS
110+
- `HTTP_PORT` (default `8080`) - HTTP (redirects to HTTPS)
111+
- `HTTPS_PORT` (default `8443`) - HTTPS
110112

111113
## Layout
112114

config/Caddyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
:80 {
2-
redir https://{$DOMAIN:localhost}:8443{uri} permanent
2+
redir https://{$DOMAIN:localhost}:{$HTTPS_PORT:8443}{uri} permanent
33
}
44

55
{$DOMAIN:localhost} {

docker-compose.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ services:
1717
dockerfile: Dockerfile.caddy
1818
container_name: ssl-proxy
1919
ports:
20-
- "8080:80"
21-
- "8443:443"
20+
- "${HTTP_PORT:-8080}:80"
21+
- "${HTTPS_PORT:-8443}:443"
2222
environment:
2323
- DOMAIN=${DOMAIN:-localhost}
2424
- UPSTREAM_URL=${UPSTREAM_URL:-http://host.docker.internal:3000}
25+
- HTTPS_PORT=${HTTPS_PORT:-8443}
2526
extra_hosts:
2627
- "host.docker.internal:host-gateway"
2728
volumes:

0 commit comments

Comments
 (0)