How to Use Caddy as a Reverse Proxy
Caddy is a powerful and user-friendly web server. One of its features is its ability to act as a reverse proxy, seamlessly directing client requests to the appropriate backend servers while offering robust security and performance benefits.
To configure caddy as reverse proxy, add following to Caddyfile
1 |
vi /etc/caddy/Caddyfile |
Add
1 2 3 4 5 6 7 8 |
serverok.in { reverse_proxy * 10.1.1.1:443 { transport http { tls tls_insecure_skip_verify } } } |
Restart Caddy
1 |
systemctl restart caddy |
In this case, all request for domain serverok.in will be proxied to backend server IP address 10.1.1.1 on port 443.
tls_insecure_skip_verify is to specify not to validate backend server SSL certificate to allow self signed SSL certificate.
To enable logging
1 2 3 4 5 6 7 8 9 10 11 |
serverok.in { reverse_proxy * 10.1.1.1:443 { transport http { tls tls_insecure_skip_verify } } log { output file /var/log/caddy/serverok.in.access.log } } |
This will save logs in JSON format.
If you need to allow multiple domains, separate them with comma.
1 2 3 4 5 6 7 8 9 10 11 |
serverok.in, www.serverok.in { reverse_proxy * 10.1.1.1:443 { transport http { tls tls_insecure_skip_verify } } log { output file /var/log/caddy/serverok.in.access.log } } |
To redirect www domain to non-www
1 2 3 |
www.serverok.in { redir https://serverok.in{uri} } |
Back to Caddy