The problem here is I have frequent requests to add subdomains and need to integrate with my app to automate the process.
For example, you’ll need to insert a new logger, maybe named `log4`, then insert a new route inside `/apps/http/servers/srv0/routes/0/handle/0/routes` with your host matcher + subroute with proxy, then add to `logger_names` a mapping of your new domain to the logger you added `log4`.
Can you give the exact curl commands for inserting the following, which will be helpful as I dont have much idea on this.
log {
hostnames demo2.app.test.com
output file /var/log/caddy/demo2.app.test.com.log
}
@demo2 host demo2.app.test.com
handle @demo2 {
reverse_proxy 0.0.0.0:11003
}
json file including these entries:
{
"logging": {
"logs": {
"default": {
"exclude": [
"http.log.access.log0",
"http.log.access.log1",
"http.log.access.log2",
"http.log.access.log3",
"http.log.access.log4"
]
},
"log0": {
"writer": {
"filename": "/var/log/caddy/demo.app.test.com.log",
"output": "file"
},
"include": [
"http.log.access.log0"
]
},
"log1": {
"writer": {
"filename": "/var/log/caddy/demo1.app.test.com.log",
"output": "file"
},
"include": [
"http.log.access.log1"
]
},
"log2": {
"writer": {
"filename": "/var/log/caddy/demo2.app.test.com.log",
"output": "file"
},
"include": [
"http.log.access.log2"
]
},
"log3": {
"writer": {
"filename": "/var/log/caddy/www.app.test.com.log",
"output": "file"
},
"include": [
"http.log.access.log3"
]
},
"log4": {
"writer": {
"filename": "/var/log/caddy/app.test.com.log",
"output": "file"
},
"include": [
"http.log.access.log4"
]
}
}
},
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":443"
],
"routes": [
{
"match": [
{
"host": [
"*.app.test.com"
]
}
],
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "static_response",
"headers": {
"Location": [
"/test"
]
},
"status_code": 302
}
],
"match": [
{
"path": [
"/"
]
}
]
},
{
"group": "group10",
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"abort": true,
"handler": "static_response"
}
]
}
]
}
],
"match": [
{
"path": [
"/test/actuator/*"
]
}
]
},
{
"group": "group10",
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "vars",
"root": "/var/www/html"
}
]
},
{
"group": "group0",
"handle": [
{
"handler": "rewrite",
"uri": "/var/www/html/robots.txt"
}
],
"match": [
{
"path": [
"/robots.txt"
]
}
]
},
{
"handle": [
{
"handler": "file_server",
"hide": [
"./Caddyfile"
]
}
]
}
]
}
],
"match": [
{
"path": [
"/robots.txt"
]
}
]
},
{
"group": "group10",
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"abort": true,
"handler": "static_response"
}
]
}
]
}
],
"match": [
{
"path": [
"/health"
]
}
]
},
{
"group": "group10",
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "reverse_proxy",
"upstreams": [
{
"dial": "0.0.0.0:11001"
}
]
}
]
}
]
}
],
"match": [
{
"host": [
"demo.app.test.com"
]
}
]
},
{
"group": "group10",
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "reverse_proxy",
"upstreams": [
{
"dial": "0.0.0.0:11002"
}
]
}
]
}
]
}
],
"match": [
{
"host": [
"demo1.app.test.com"
]
}
]
},
{
"group": "group10",
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "reverse_proxy",
"upstreams": [
{
"dial": "0.0.0.0:11003"
}
]
}
]
}
]
}
],
"match": [
{
"host": [
"demo2.app.test.com"
]
}
]
},
{
"group": "group10",
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "vars",
"root": "/var/www/html"
}
]
},
{
"group": "group6",
"handle": [
{
"handler": "rewrite",
"uri": "www.html"
}
],
"match": [
{
"path": [
"/test"
]
}
]
},
{
"handle": [
{
"handler": "file_server",
"hide": [
"./Caddyfile"
]
}
]
}
]
}
],
"match": [
{
"host": [
"www.app.test.com"
]
}
]
},
{
"group": "group10",
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "vars",
"root": "/var/www/html"
}
]
},
{
"group": "group7",
"handle": [
{
"handler": "rewrite",
"uri": "www.html"
}
],
"match": [
{
"path": [
"/test"
]
}
]
},
{
"handle": [
{
"handler": "file_server",
"hide": [
"./Caddyfile"
]
}
]
}
]
}
],
"match": [
{
"host": [
"app.test.com"
]
}
]
},
{
"group": "group10",
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "static_response",
"headers": {
"Location": [
"https://www.app.test.com"
]
},
"status_code": 302
}
]
}
]
}
]
}
]
}
],
"terminal": true
}
],
"errors": {
"routes": [
{
"match": [
{
"host": [
"*.app.test.com"
]
}
],
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "vars",
"root": "/var/www/html"
}
]
},
{
"group": "group9",
"handle": [
{
"handler": "rewrite",
"uri": "maintenance.html"
}
],
"match": [
{
"expression": "{http.error.status_code} == 502"
}
]
},
{
"handle": [
{
"handler": "file_server",
"hide": [
"./Caddyfile"
]
}
]
}
]
}
],
"terminal": true
}
]
},
"tls_connection_policies": [
{
"match": {
"sni": [
"*.app.test.com"
]
},
"certificate_selection": {
"any_tag": [
"cert0"
]
}
},
{}
],
"logs": {
"logger_names": {
"app.test.com": "log4",
"demo.app.test.com": "log0",
"demo1.app.test.com": "log1",
"demo2.app.test.com": "log2",
"www.app.test.com": "log3"
}
}
}
}
},
"tls": {
"certificates": {
"load_files": [
{
"certificate": "/etc/letsencrypt/live/app.test.com/fullchain.pem",
"key": "/etc/letsencrypt/live/app.test.com/privkey.pem",
"tags": [
"cert0"
]
}
]
}
}
}
}