Self-hosted website using Google Domains, Caddy Server, and Cloudflare in a Windows environment.
Startup your webservice like Jellyfin or Photoprism. This is your <target>.
- Assign / reserve a static IP for your host machine.
- Forward port 443 to this IP.
Choose any you'd like. As of 2023, some .com and .org domains can be purchased for as low as $12 per year.
- Create a new website. Name it the domain name.
- DNS -> records -> add new
Arecord.Name: <your domain name> # example: myselfhost.dev IPv4 address: <your public IP> Proxy status: Proxied TTL: Auto - (Optional) Add a new
CNAMErecord.Name: <subdomain> # example: media Target: @ Proxy status: Proxied TTL: Auto - SSL -> Overview -> Change TLS encryption mode to Full (strict).
- Top right -> My Profile -> API Tokens -> Create Token ->
Create Custom Token
This is your
Token name: Caddy API token Permissions: - Zone.Zone.Read - Zone.DNS.Edit Zone Resources: - Include.Specific Zone.<your domain name><api_token> - Go to Cloudflare Nameserver section and take note of these two names.
For example, it should look like
something.ns.cloudflare.com
- Click your domain -> DNS -> Custom Name servers tab
- Make sure to click "Switch to Custom Name servers" link
- Add the two name servers from the above
- Go to https://caddyserver.com/ and click Download
- Click
caddy-dns/cloudflaremodule (it'll highlight blue and the "Extra features" number will change to 1. - Download and rename to
caddy.exe. - Copy this file into some directory for example:
C:\website - Copy from this repo
./config/Caddyfileinto the above directory. - Update this file with:
- Your
<api_token>. - Your
<target>. This is the target web server on your machine. - Your
<host_name>. This is the domain/subdomain you are listening on.
- Your
- Go to https://nssm.cc/download and download the binary
- Extract and run
nssm.exe install. - A new window will open. Fill it out with these details:
Application tab --- Program: C:\website\caddy.exe Start in: C:\website\ Arguments: run --config Caddyfile Service name: Caddy Details tab --- Display Name: Caddy Server Startup type: Automatic - Click save. This will install the service.
nssm.exe run Caddywill start the service.
- If you haven't already, download and install Powershell 7.1+.
- Copy
.\scripts\*.ps1files toC:\website\scripts. - Update
schedule_task.ps1:<script_path>this is the absolute path to the powershell scripts.<email>this is the email you used for Cloudflare.<api_token>this is the same token as before.<dns_domain>this is the domain name you registered.<dns_record>this is the record to update.
- Run
schedule_task.ps1. This schedules a task every 30 minutes to runrefresh_ip.ps1, which will update Cloudflare of any changes in your public IP. s
Make sure to change your SSL settings in CLoudflare to Full (strict).