diff --git a/caddy/pokemon.Caddyfile b/caddy/pokemon.Caddyfile new file mode 100644 index 0000000..7379838 --- /dev/null +++ b/caddy/pokemon.Caddyfile @@ -0,0 +1,15 @@ +pokemon.domain-name.com { + reverse_proxy :8080 # Assuming the application is running at PORT 8080 + + handle_errors { + root * /var/www + rewrite * /error.html + templates + file_server + } +} + +# just domain name looks much cleaner +www.pokemon.domain-name.com { + redir pokemon.domain-name.com{uri} +} diff --git a/caddy/readme.md b/caddy/readme.md index 5614851..3707816 100644 --- a/caddy/readme.md +++ b/caddy/readme.md @@ -59,3 +59,19 @@ We can setup seperate error pages for different kind of error. But I'll be using For reference look at [error.html](./error.html) file. To learn more about it check the Caddy docs **RTFM** about [handling errors](https://caddyserver.com/docs/caddyfile/directives/handle_errors). + +## Reverse Proxy + +**Most of the devs don't know what reverse proxy is. So maybe [check this](https://en.wikipedia.org/wiki/Reverse_proxy) out.** + +Lets say we have `pokemon` API running on PORT `8080` and we want any traffic coming to subdomain `pokemon.domain-name.com` to be redirected to the pokemon server. +To achieve this we can setup reverse proxy for this subdomain. +To setup reverse proxy first we need to set `A Record` of sub-domain to the IP address of the VPS. +Then we can define the reverse proxy in our caddy config like mentioned below. + +```Caddyfile +pokemon.domain-name.com { + reverse_proxy :8080 +} +``` +Checkout this sample reverse proxy [config](./pokemon.Caddyfile) and ofc read [caddy docs](https://caddyserver.com/docs/quick-starts/reverse-proxy) to check what else you can do with reverse proxy.