diff --git a/v2:-Caddyfile-examples.md b/v2:-Caddyfile-examples.md new file mode 100644 index 0000000..68b00fb --- /dev/null +++ b/v2:-Caddyfile-examples.md @@ -0,0 +1,132 @@ +# Caddyfile configuration examples + +Caddyfile configuration is easy and convenient and Caddy v2 configuration has changed a little, but for the better. Hence, below there are some configuration examples for common use cases. + +Feel free to add your Caddyfile configuration, too. + +## Simple local static fileserver with php support +Configuring Caddy as a simple and local static HTTP fileserver that can also run PHP can look like this: +``` +{ + handler_order appearance +} + +:8080 { + +root * /path/to/webfolder + +encode gzip + +php_fastcgi php-fpm:9000 + +file_server + +} +``` +The converted equivalant (_./caddy adapt-config --input /path/to/Caddyfile --adapter caddyfile --pretty_) in json looks like this: + +``` +{ + "apps": { + "http": { + "servers": { + "srv0": { + "listen": [ + ":8080" + ], + "routes": [ + { + "handle": [ + { + "handler": "subroute", + "routes": [ + { + "handle": [ + { + "handler": "vars", + "root": "/path/to/webfolder" + }, + { + "handler": "subroute", + "routes": [ + { + "handle": [ + { + "encodings": { + "gzip": {} + }, + "handler": "encode" + } + ] + }, + { + "handle": [ + { + "handler": "rewrite", + "rehandle": true, + "uri": "{http.matchers.file.relative}{http.request.uri.query_string}" + } + ], + "match": [ + { + "file": { + "try_files": [ + "{http.request.uri.path}", + "index.php" + ] + } + } + ] + }, + { + "handle": [ + { + "handler": "reverse_proxy", + "transport": { + "protocol": "fastcgi", + "split_path": ".php" + }, + "upstreams": [ + { + "dial": "php-fpm:9000" + } + ] + } + ], + "match": [ + { + "path": [ + "*.php" + ] + } + ] + }, + { + "handle": [ + { + "handler": "file_server", + "hide": [ + "Caddyfile" + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + } + }, + "tls": { + "automation": {}, + "session_tickets": {} + } + } +} +``` \ No newline at end of file