This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
esxi:caddy_server [2020/07/03 15:36] derek created |
esxi:caddy_server [2024/09/22 19:51] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
=====Caddy Server===== | =====Caddy Server===== | ||
- | FIXME: Explain | + | Caddy is a reverse proxy and lightweight webserver that automatically acquires and uses https certificates. |
+ | Caddy is used here to host a list of links, | ||
====Setup==== | ====Setup==== | ||
- | First, install | + | * Set up DNS with Cloudflare using [[web: |
+ | * For each domain used: | ||
+ | * Navigate to each domain > '' | ||
+ | * Add wildcard CNAME record: | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * Add a ' | ||
+ | * If not using a wildcard CNAME record, add a CNAME record for the desired subdomain as above | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | Install | ||
* Hostname: '' | * Hostname: '' | ||
* CPU: 1 | * CPU: 1 | ||
Line 11: | Line 32: | ||
===Install Caddy Server:=== | ===Install Caddy Server:=== | ||
- | * Add a port forwarding rule in your router for tcp, port '' | + | * Add a port forwarding rule in your router for tcp, port: '' |
* Using an SSH client, connect to < | * Using an SSH client, connect to < | ||
<code bash> | <code bash> | ||
- | # FIXME: | + | # Allow http/https through iptables |
- | printf | + | sed -i "s/COMMIT/-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT\n-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT\nCOMMIT/" / |
- | printf "-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT" | + | reboot |
- | # Download Caddy | + | # Add the caddy group and user |
- | tdnf install tar | + | |
- | mkdir / | + | |
- | cd / | + | |
- | # Copy the link for the " | + | |
- | curl -OL "< | + | |
- | tar -xzf < | + | |
- | mv caddy /usr/bin/ | + | |
- | cd / | + | |
- | rm -r / | + | |
- | + | ||
- | # Add caddy group/user | + | |
groupadd --system caddy | groupadd --system caddy | ||
useradd --system \ | useradd --system \ | ||
Line 40: | Line 50: | ||
caddy | caddy | ||
- | # Setup startup | + | cd /usr/bin |
- | cd /etc/systemd/ | + | |
- | curl -OL " | + | |
- | systemctl daemon-reload | + | |
- | systemctl enable caddy | + | |
- | # Config file | + | # Download Caddy |
- | mkdir /etc/caddy | + | curl -L -o "caddy" " |
- | chmod 755 /etc/caddy | + | chmod 755 caddy |
- | cd /etc/caddy | + | |
- | # FIXME: Download Caddyfile | + | |
- | chmod 644 Caddyfile | + | |
- | systemctl start caddy | + | # Config file and html pages |
+ | curl -L -o " | ||
+ | chmod u+x fetch | ||
+ | # Generate a GitHub Personal Access Token at https:// | ||
+ | # Enter the key when this command asks | ||
+ | read -rp "Enter github api token: " token && echo " | ||
+ | # Reload the shell so it exports the tokens in this session | ||
+ | exec $SHELL | ||
- | # View the Caddy log | + | fetch --repo=" |
- | journalctl | + | chmod -R a=r,u+w,a+X /etc/caddy |
- | # Use updated config | + | # Setup caddy startup service |
- | systemctl | + | curl -L -o / |
+ | systemctl daemon-reload | ||
+ | |||
+ | # Get a DNS API token from https:// | ||
+ | # Edit zone DNS > Use template: | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # Edit zone DNS > Use template: | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | |||
+ | # Set up Google OAuth 2.0: | ||
+ | # Go to: [[https:// | ||
+ | # | ||
+ | # | ||
+ | |||
+ | systemctl edit caddy | ||
+ | # Paste in the following lines with their respective keys filled in: | ||
+ | [Service] | ||
+ | Environment=" | ||
+ | Environment=" | ||
+ | Environment=" | ||
+ | Environment=" | ||
+ | # Then save and exit the file with: ESC, :wq | ||
+ | |||
+ | # Enable and run the Caddy service | ||
+ | systemctl | ||
</ | </ | ||
* Edit the VM note and append the following: | * Edit the VM note and append the following: | ||
< | < | ||
+ | 80,443/tcp Http,Https Caddy | ||
</ | </ | ||
* Save a snapshot called '' | * Save a snapshot called '' | ||
+ | |||
+ | ====Notes==== | ||
+ | <code bash> | ||
+ | # View the Caddy log (add -n <num> to see the latest <num> entries, or -f to actively follow the log) | ||
+ | journalctl -u caddy | ||
+ | |||
+ | # Use updated config file | ||
+ | systemctl reload caddy | ||
+ | </ | ||
+ | |||
+ | Edit the Caddyfile at [[https:// | ||
+ | |||
+ | Services that require setting Trusted Proxies: | ||
+ | * [[esxi: | ||
+ | * [[home:Home Assistant]] | ||
+ | * [[esxi:AMP Game Server]] | ||
+ | |||
+ | @No_Backup | ||
====Update==== | ====Update==== | ||
{{page> | {{page> | ||
- | * FIXME: Describe update Process | + | Check for updates and changelogs from: [[https:// |
- | * Include in update all page using '' | + | |
<code bash> | <code bash> | ||
- | # Copy the link for the "caddy_2.x.x_linux_amd64.tar.gz" | + | # Check the current running version |
- | curl -OL "< | + | caddy version |
- | tar -xzf < | + | |
- | mv caddy /usr/bin/ | + | # Update Caddy |
- | cd / | + | caddy update |
- | rm -r /tmp/caddy | + | chmod 755 / |
+ | systemctl reload caddy | ||
+ | |||
+ | # Once a year generate a GitHub Personal Access Token at https:// | ||
+ | # Enter the key when this command asks | ||
+ | read -rp "Enter api token: " token && echo " | ||
+ | # Reload the shell so it exports the tokens in this session | ||
+ | exec $SHELL | ||
+ | |||
+ | # Update just the Caddy config | ||
+ | fetch --repo=" | ||
+ | |||
+ | # Update Config and HTML | ||
+ | # Remove old folder if any files have been deleted/moved/ | ||
+ | rm -r / | ||
+ | fetch --repo="https:// | ||
+ | chmod -R a=r, | ||
+ | |||
+ | # Test updated Caddyfile | ||
+ | caddy validate --config / | ||
+ | |||
+ | # Use updated config file | ||
+ | systemctl reload | ||
</ | </ | ||
====Sources==== | ====Sources==== | ||
* [[https:// | * [[https:// |