Created
June 27, 2025 07:27
-
-
Save naufalso/9ad2c9631cce515d4e5a6113651c9be1 to your computer and use it in GitHub Desktop.
Caddy Port Forward
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
if [ $# -lt 1 ]; then | |
echo "Usage: $0 portin1|output1 [portin2|output2 ...]" | |
exit 1 | |
fi | |
for pair in "$@"; do | |
# Split on the '|' delimiter into an array of two elements | |
IFS='|' read -r portin output <<< "$pair" # [oai_citation:0‡stackoverflow.com](https://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash?utm_source=chatgpt.com) | |
if [[ -z $portin || -z $output ]]; then | |
echo "Invalid pair: '$pair'. Must be in the form portin|output" | |
continue | |
fi | |
echo "Starting proxy from :${portin} to ${output}…" | |
# Launch each proxy in the background (remove '&' if you want sequential/blocking) | |
caddy reverse-proxy --from ":${portin}" --to "${output}" & | |
done | |
wait | |
echo "All caddy reverse-proxy instances are running." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment