Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 11, 01:00 UTC
| 1 | :8884 |
| 2 | |
| 3 | reverse_proxy 127.0.0.1:65535 { |
| 4 | lb_retries 5 |
| 5 | |
| 6 | # request matchers (backward-compatible, non-expression) |
| 7 | lb_retry_match { |
| 8 | method POST PUT |
| 9 | } |
| 10 | lb_retry_match { |
| 11 | path /foo* |
| 12 | } |
| 13 | lb_retry_match { |
| 14 | header X-Idempotency-Key * |
| 15 | } |
| 16 | |
| 17 | # response status code via expression |
| 18 | lb_retry_match { |
| 19 | expression `{rp.status_code} in [502, 503, 504]` |
| 20 | } |
| 21 | |
| 22 | # response header via expression |
| 23 | lb_retry_match { |
| 24 | expression `{rp.header.X-Retry} == "true"` |
| 25 | } |
| 26 | |
| 27 | # CEL request functions combined with response placeholders |
| 28 | lb_retry_match { |
| 29 | expression `method('POST') && {rp.status_code} >= 500` |
| 30 | } |
| 31 | lb_retry_match { |
| 32 | expression `path('/api*') && {rp.status_code} in [502, 503]` |
| 33 | } |
| 34 | lb_retry_match { |
| 35 | expression `host('example.com') && {rp.status_code} == 503` |
| 36 | } |
| 37 | lb_retry_match { |
| 38 | expression `query({'retry': 'true'}) && {rp.status_code} >= 500` |
| 39 | } |
| 40 | lb_retry_match { |
| 41 | expression `header({'X-Idempotency-Key': '*'}) && {rp.status_code} in [502, 503]` |
| 42 | } |
| 43 | lb_retry_match { |
| 44 | expression `protocol('https') && {rp.status_code} == 502` |
| 45 | } |
| 46 | lb_retry_match { |
| 47 | expression `path_regexp('^/api/v[0-9]+/') && {rp.status_code} >= 500` |
| 48 | } |
| 49 | lb_retry_match { |
| 50 | expression `header_regexp('Content-Type', '^application/json') && {rp.status_code} == 502` |
| 51 | } |
| 52 | |
| 53 | # transport error handling via placeholder |
| 54 | lb_retry_match { |
| 55 | expression `{rp.is_transport_error} || {rp.status_code} in [502, 503]` |
| 56 | } |
| 57 | lb_retry_match { |
| 58 | expression `{rp.is_transport_error} && method('POST')` |
| 59 | } |
| 60 | } |
| 61 | ---------- |
| 62 | { |
| 63 | "apps": { |
| 64 | "http": { |
| 65 | "servers": { |
| 66 | "srv0": { |
| 67 | "listen": [ |
| 68 | ":8884" |
| 69 | ], |
| 70 | "routes": [ |
| 71 | { |
| 72 | "handle": [ |
| 73 | { |
| 74 | "handler": "reverse_proxy", |
| 75 | "load_balancing": { |
| 76 | "retries": 5, |
| 77 | "retry_match": [ |
| 78 | { |
| 79 | "method": [ |
| 80 | "POST", |
| 81 | "PUT" |
| 82 | ] |
| 83 | }, |
| 84 | { |
| 85 | "path": [ |
| 86 | "/foo*" |
| 87 | ] |
| 88 | }, |
| 89 | { |
| 90 | "header": { |
| 91 | "X-Idempotency-Key": [ |
| 92 | "*" |
| 93 | ] |
| 94 | } |
| 95 | }, |
| 96 | { |
| 97 | "expression": "{http.reverse_proxy.status_code} in [502, 503, 504]" |
| 98 | }, |
| 99 | { |
| 100 | "expression": "{http.reverse_proxy.header.X-Retry} == \"true\"" |
| 101 | }, |
| 102 | { |
| 103 | "expression": "method('POST') \u0026\u0026 {http.reverse_proxy.status_code} \u003e= 500" |
| 104 | }, |
| 105 | { |
| 106 | "expression": "path('/api*') \u0026\u0026 {http.reverse_proxy.status_code} in [502, 503]" |
| 107 | }, |
| 108 | { |
| 109 | "expression": "host('example.com') \u0026\u0026 {http.reverse_proxy.status_code} == 503" |
| 110 | }, |
| 111 | { |
| 112 | "expression": "query({'retry': 'true'}) \u0026\u0026 {http.reverse_proxy.status_code} \u003e= 500" |
| 113 | }, |
| 114 | { |
| 115 | "expression": "header({'X-Idempotency-Key': '*'}) \u0026\u0026 {http.reverse_proxy.status_code} in [502, 503]" |
| 116 | }, |
| 117 | { |
| 118 | "expression": "protocol('https') \u0026\u0026 {http.reverse_proxy.status_code} == 502" |
| 119 | }, |
| 120 | { |
| 121 | "expression": "path_regexp('^/api/v[0-9]+/') \u0026\u0026 {http.reverse_proxy.status_code} \u003e= 500" |
| 122 | }, |
| 123 | { |
| 124 | "expression": "header_regexp('Content-Type', '^application/json') \u0026\u0026 {http.reverse_proxy.status_code} == 502" |
| 125 | }, |
| 126 | { |
| 127 | "expression": "{http.reverse_proxy.is_transport_error} || {http.reverse_proxy.status_code} in [502, 503]" |
| 128 | }, |
| 129 | { |
| 130 | "expression": "{http.reverse_proxy.is_transport_error} \u0026\u0026 method('POST')" |
| 131 | } |
| 132 | ] |
| 133 | }, |
| 134 | "upstreams": [ |
| 135 | { |
| 136 | "dial": "127.0.0.1:65535" |
| 137 | } |
| 138 | ] |
| 139 | } |
| 140 | ] |
| 141 | } |
| 142 | ] |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | } |