brennan revised this gist 1 month ago. Go to revision
1 file changed, 2 insertions, 2 deletions
simple-windows-hosting.md
| @@ -1,7 +1,7 @@ | |||
| 1 | - | 1. Get your site files | |
| 1 | + | 1. Get yr site files ready | |
| 2 | 2 | ||
| 3 | 3 | ``` | |
| 4 | - | readymkdir C:\sites\skaia-library | |
| 4 | + | mkdir C:\sites\skaia-library | |
| 5 | 5 | ``` | |
| 6 | 6 | ||
| 7 | 7 | Drop yr `index.html` in there. | |
brennan revised this gist 1 month ago. Go to revision
1 file changed, 70 insertions
simple-windows-hosting.md(file created)
| @@ -0,0 +1,70 @@ | |||
| 1 | + | 1. Get your site files | |
| 2 | + | ||
| 3 | + | ``` | |
| 4 | + | readymkdir C:\sites\skaia-library | |
| 5 | + | ``` | |
| 6 | + | ||
| 7 | + | Drop yr `index.html` in there. | |
| 8 | + | ||
| 9 | + | 2. Install Caddy | |
| 10 | + | ||
| 11 | + | Easiest is `scoop install caddy` with https://scoop.sh/, or grab the binary directly from caddyserver.com/download. No need for the caddy_windows_amd64.exe build with plugins. | |
| 12 | + | ||
| 13 | + | 3. Caddyfile | |
| 14 | + | ||
| 15 | + | Since Cloudflare Tunnel will handle the public-facing TLS, Caddy only needs to serve locally, so no need for its automatic HTTPS: | |
| 16 | + | ||
| 17 | + | ``` | |
| 18 | + | :8080 { | |
| 19 | + | root * C:\sites\skaia-library | |
| 20 | + | file_server | |
| 21 | + | } | |
| 22 | + | ``` | |
| 23 | + | ||
| 24 | + | Run it from that directory: `caddy run --config Caddyfile` | |
| 25 | + | ||
| 26 | + | 4. Install cloudflared | |
| 27 | + | ||
| 28 | + | `winget install --id Cloudflare.cloudflared -e` (or grab the .exe from the cloudflared GitHub releases page). | |
| 29 | + | ||
| 30 | + | 5. Authenticate | |
| 31 | + | ||
| 32 | + | Run `cloudflared tunnel login` in the cmd. | |
| 33 | + | ||
| 34 | + | This will pop up a browser window, log in and pick the zone (domain) you want to authorize. | |
| 35 | + | ||
| 36 | + | 6. Create the tunnel | |
| 37 | + | ||
| 38 | + | `cloudflared tunnel create skaia-tunnel` | |
| 39 | + | ||
| 40 | + | This will generate a tunnel UUID and drops a credentials JSON in `%USERPROFILE%\.cloudflared\`. | |
| 41 | + | ||
| 42 | + | 7. Route a hostname to it | |
| 43 | + | ||
| 44 | + | `cloudflared tunnel route dns mysite-tunnel sub.skaia-library.xyz` | |
| 45 | + | ||
| 46 | + | This will create the CNAME in Cloudflare DNS pointing at `<UUID>.cfargotunnel.com`. | |
| 47 | + | ||
| 48 | + | 8. Create the config file at `%USERPROFILE%\.cloudflared\config.yml`: | |
| 49 | + | ||
| 50 | + | ``` | |
| 51 | + | yamltunnel: skaia-tunnel | |
| 52 | + | credentials-file: C:\Users\YOURNAME\.cloudflared\<UUID>.json | |
| 53 | + | ||
| 54 | + | ingress: | |
| 55 | + | - hostname: sub.skaia-library.xyz | |
| 56 | + | service: http://localhost:8080 | |
| 57 | + | - service: http_status:404 | |
| 58 | + | ``` | |
| 59 | + | ||
| 60 | + | 9. Run it! | |
| 61 | + | ||
| 62 | + | `cloudflared tunnel run skaia-tunnel` | |
| 63 | + | ||
| 64 | + | Site should now be live at `sub.skaia-library.xyz`, proxied through Cloudflare. | |
| 65 | + | ||
| 66 | + | 10. Make it persistent | |
| 67 | + | ||
| 68 | + | `cloudflared service install` registers cloudflared as a Windows service using that config.yml which means it'll survive reboots. | |
| 69 | + | ||
| 70 | + | Caddy doesn't have a built-in Windows service installer, it will need to run with Task Scheduler at logon/startup, or use NSSM (nssm install caddy) to wrap it as a proper service. https://nssm.cc/ | |