diff --git a/src/core.sh b/src/core.sh index 7359f2e..e7d35a2 100644 --- a/src/core.sh +++ b/src/core.sh @@ -161,8 +161,11 @@ update_caddyfile_fallback() { # 2. Replace any site block headers explicit :443 with :4443 sed -i 's/:443[[:space:]]*{/:4443 {/g' $is_caddyfile - # 3. Add https_port 4443 to global block if not present - if [[ ! $(grep "https_port 4443" $is_caddyfile) ]]; then + # 3. Add or update https_port 4443 in global block + if [[ $(grep "https_port" $is_caddyfile) ]]; then + # Replace existing https_port with 4443 + sed -i 's/https_port[[:space:]]\+[0-9]\+/https_port 4443/g' $is_caddyfile + else # Find first { and insert https_port 4443 on the next line sed -i '0,/^[[:space:]]*{[[:space:]]*$/s//{\n https_port 4443/' $is_caddyfile fi