Updated v2: Config from Scratch (markdown)

Matt Holt 2019-07-03 13:26:58 -06:00
parent 8f4d2389ae
commit 21497d9397

@ -1,78 +1,72 @@
Empty config (does nothing):
An empty config does nothing:
```json
{}
```
Empty HTTP server (responds with empty responses):
This is an empty HTTP server, which responds on port 80 to any host, but with an empty response:
```json
{
"apps": {
"http": {
"servers": {
"myserver": {
"listen": [":80"],
}
}
}
}
"apps": {
"http": {
"servers": {
"myserver": {
"listen": [":80"],
}
}
}
}
}
```
Static file server out of the specified directory:
This is a static file server out of the the `/var/www` directory:
```json
{
"apps": {
"http": {
"servers": {
"myserver": {
"listen": [":80"],
"routes": [
{
"respond": {
"responder": "file_server",
"root": "/var/www"
}
}
]
}
}
}
}
"apps": {
"http": {
"servers": {
"myserver": {
"listen": [":80"],
"routes": [
{
"respond": {
"responder": "file_server",
"root": "/var/www"
}
}
]
}
}
}
}
}
```
Same as above, but with automatic HTTPS (including HTTP->HTTPS redirects):
And this is the same, but with automatic HTTPS (notice that we now serve on the HTTPS port; any port will do, as long as it's not the HTTP port):
```json
{
"apps": {
"http": {
"servers": {
"myserver": {
"listen": [":443"],
"routes": [
{
"match": [
{
"host": ["example.com"]
}
],
"respond": {
"responder": "file_server",
"root": "/var/www"
}
}
]
}
}
}
}
"apps": {
"http": {
"servers": {
"myserver": {
"listen": [":443"],
"routes": [
{
"match": [{"host": ["example.com"]}],
"respond": {
"responder": "file_server",
"root": "/var/www"
}
}
]
}
}
}
}
}
```
The reason the above config uses HTTPS is because the host matcher informs Caddy which hostnames to manage certificates for.
The reason this particular config gets automatic HTTPS is because the host matcher informs Caddy which hostnames to manage certificates for.