reverse proxy
This commit is contained in:
15
caddy/pokemon.Caddyfile
Normal file
15
caddy/pokemon.Caddyfile
Normal file
@@ -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}
|
||||||
|
}
|
||||||
@@ -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.
|
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).
|
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.
|
||||||
|
|||||||
Reference in New Issue
Block a user