mirror of
https://github.com/caddyserver/caddy.git
synced 2025-07-09 03:04:57 -04:00
Initial creation of document :-)
parent
c85da3901a
commit
57d38c3e76
132
v2:-Caddyfile-examples.md
Normal file
132
v2:-Caddyfile-examples.md
Normal file
@ -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": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
Loading…
x
Reference in New Issue
Block a user