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 | example.com { |
| 2 | root * /srv |
| 3 | |
| 4 | # Trigger errors for certain paths |
| 5 | error /private* "Unauthorized" 403 |
| 6 | error /hidden* "Not found" 404 |
| 7 | |
| 8 | # Handle the error by serving an HTML page |
| 9 | handle_errors { |
| 10 | rewrite * /{http.error.status_code}.html |
| 11 | file_server |
| 12 | } |
| 13 | |
| 14 | file_server |
| 15 | } |
| 16 | ---------- |
| 17 | { |
| 18 | "apps": { |
| 19 | "http": { |
| 20 | "servers": { |
| 21 | "srv0": { |
| 22 | "listen": [ |
| 23 | ":443" |
| 24 | ], |
| 25 | "routes": [ |
| 26 | { |
| 27 | "match": [ |
| 28 | { |
| 29 | "host": [ |
| 30 | "example.com" |
| 31 | ] |
| 32 | } |
| 33 | ], |
| 34 | "handle": [ |
| 35 | { |
| 36 | "handler": "subroute", |
| 37 | "routes": [ |
| 38 | { |
| 39 | "handle": [ |
| 40 | { |
| 41 | "handler": "vars", |
| 42 | "root": "/srv" |
| 43 | } |
| 44 | ] |
| 45 | }, |
| 46 | { |
| 47 | "handle": [ |
| 48 | { |
| 49 | "error": "Unauthorized", |
| 50 | "handler": "error", |
| 51 | "status_code": 403 |
| 52 | } |
| 53 | ], |
| 54 | "match": [ |
| 55 | { |
| 56 | "path": [ |
| 57 | "/private*" |
| 58 | ] |
| 59 | } |
| 60 | ] |
| 61 | }, |
| 62 | { |
| 63 | "handle": [ |
| 64 | { |
| 65 | "error": "Not found", |
| 66 | "handler": "error", |
| 67 | "status_code": 404 |
| 68 | } |
| 69 | ], |
| 70 | "match": [ |
| 71 | { |
| 72 | "path": [ |
| 73 | "/hidden*" |
| 74 | ] |
| 75 | } |
| 76 | ] |
| 77 | }, |
| 78 | { |
| 79 | "handle": [ |
| 80 | { |
| 81 | "handler": "file_server", |
| 82 | "hide": [ |
| 83 | "./Caddyfile" |
| 84 | ] |
| 85 | } |
| 86 | ] |
| 87 | } |
| 88 | ] |
| 89 | } |
| 90 | ], |
| 91 | "terminal": true |
| 92 | } |
| 93 | ], |
| 94 | "errors": { |
| 95 | "routes": [ |
| 96 | { |
| 97 | "match": [ |
| 98 | { |
| 99 | "host": [ |
| 100 | "example.com" |
| 101 | ] |
| 102 | } |
| 103 | ], |
| 104 | "handle": [ |
| 105 | { |
| 106 | "handler": "subroute", |
| 107 | "routes": [ |
| 108 | { |
| 109 | "handle": [ |
| 110 | { |
| 111 | "handler": "subroute", |
| 112 | "routes": [ |
| 113 | { |
| 114 | "group": "group0", |
| 115 | "handle": [ |
| 116 | { |
| 117 | "handler": "rewrite", |
| 118 | "uri": "/{http.error.status_code}.html" |
| 119 | } |
| 120 | ] |
| 121 | }, |
| 122 | { |
| 123 | "handle": [ |
| 124 | { |
| 125 | "handler": "file_server", |
| 126 | "hide": [ |
| 127 | "./Caddyfile" |
| 128 | ] |
| 129 | } |
| 130 | ] |
| 131 | } |
| 132 | ] |
| 133 | } |
| 134 | ] |
| 135 | } |
| 136 | ] |
| 137 | } |
| 138 | ], |
| 139 | "terminal": true |
| 140 | } |
| 141 | ] |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | } |