Shubhambhandari commited on
Commit
f0ba50a
·
verified ·
1 Parent(s): e49960e

Upload setup_domain.sh

Browse files
Files changed (1) hide show
  1. setup_domain.sh +41 -0
setup_domain.sh ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # Put Pathify behind a domain with automatic free HTTPS (Caddy + Let's Encrypt).
3
+ # Run AFTER the domain's DNS already points to this VM's public IP.
4
+ # Usage (on the VM): curl -sL <this-url> | sudo bash -s -- your.domain
5
+ set -euo pipefail
6
+ DOMAIN="${1:?usage: setup_domain.sh <domain>}"
7
+
8
+ echo "[pathify] moving the app to internal port 8080..."
9
+ sed -i 's/--port 80 /--port 8080 /' /etc/systemd/system/pathify.service
10
+ systemctl daemon-reload
11
+ systemctl restart pathify
12
+
13
+ echo "[pathify] opening firewall for 80 and 443..."
14
+ for p in 80 443; do
15
+ iptables -D INPUT -p tcp -m state --state NEW -m tcp --dport "$p" -j ACCEPT 2>/dev/null || true
16
+ iptables -I INPUT 1 -p tcp -m state --state NEW -m tcp --dport "$p" -j ACCEPT
17
+ done
18
+ netfilter-persistent save || true
19
+
20
+ echo "[pathify] installing Caddy (auto-HTTPS reverse proxy)..."
21
+ export DEBIAN_FRONTEND=noninteractive
22
+ apt-get install -y debian-keyring debian-archive-keyring apt-transport-https curl gnupg >/dev/null
23
+ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
24
+ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' \
25
+ | tee /etc/apt/sources.list.d/caddy-stable.list >/dev/null
26
+ apt-get update -y >/dev/null
27
+ apt-get install -y caddy >/dev/null
28
+
29
+ echo "[pathify] configuring HTTPS for $DOMAIN..."
30
+ cat >/etc/caddy/Caddyfile <<EOF
31
+ $DOMAIN {
32
+ reverse_proxy 127.0.0.1:8080
33
+ }
34
+ EOF
35
+ systemctl restart caddy
36
+
37
+ echo "=================================================================="
38
+ echo " Done. Caddy is fetching a free certificate now (~30-60 seconds)."
39
+ echo " Then open: https://$DOMAIN"
40
+ echo " Check Caddy: sudo journalctl -u caddy --no-pager | tail -20"
41
+ echo "=================================================================="