diff --git a/v2:-Caddyfile-examples.md b/v2:-Caddyfile-examples.md index 79f3801..46bf713 100644 --- a/v2:-Caddyfile-examples.md +++ b/v2:-Caddyfile-examples.md @@ -114,7 +114,7 @@ encode gzip php_fastcgi unix//path/to/php.sock file_server ``` -The converted equivalant (`caddy adapt --config /path/to/Caddyfile --pretty_) in JSON looks like this: +The converted equivalant (`caddy adapt --config /path/to/Caddyfile --pretty`) in JSON looks like this: ``` { "apps": { @@ -203,4 +203,87 @@ The converted equivalant (`caddy adapt --config /path/to/Caddyfile --pretty_) in } } } -``` \ No newline at end of file +``` +## Reverse proxy to HTTP golang servers on port 8080 with automatic TLS and health checks + +Configuring Caddy as a reverse proxy to HTTP golang servers on port 8080 with automatic TLS and health checks can look like this: +``` +yourdomain.com, www.yourdomain.com + +reverse_proxy / { + to 192.101.153.159:8080 192.118.109.166:8080 + health_path /health + health_status 200 + transport http { + read_buffer 4096 + } +} +``` +The converted equivalant (`caddy adapt --config /path/to/Caddyfile --pretty`) in JSON looks like this: +``` +{ + "apps":{ + "http":{ + "servers":{ + "srv0":{ + "listen":[ + ":443" + ], + "routes":[ + { + "match":[ + { + "host":[ + "yourdomain.com", + "www.yourdomain.com" + ] + } + ], + "handle":[ + { + "handler":"subroute", + "routes":[ + { + "handle":[ + { + "handler":"reverse_proxy", + "health_checks":{ + "active":{ + "expect_status":2, + "path":"/health" + } + }, + "transport":{ + "protocol":"http", + "read_buffer_size":4096 + }, + "upstreams":[ + { + "dial":"192.101.153.159:8080" + }, + { + "dial":"192.118.109.166:8080" + } + ] + } + ], + "match":[ + { + "path":[ + "/" + ] + } + ] + } + ] + } + ] + } + ] + } + } + } + } +} +``` +**Note:** do not forget to set up health handlers for the golang webservers returning an HTTP 200 response or Caddy 2 will fail the health check and deem the node unreachable. \ No newline at end of file