Loading...
Loading...
Compare original and translation side by side
localhost:2019localhost:2019myapp-x7k2NAME="$(basename "$PWD" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g')-$(head -c4 /dev/urandom | xxd -p | head -c4)"myapp-x7k2NAME="$(basename "$PWD" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g')-$(head -c4 /dev/urandom | xxd -p | head -c4)"| Task | Command |
|---|---|
| Check status | |
| List routes | |
| Add route | |
| Delete route | |
| 任务 | 命令 |
|---|---|
| 检查状态 | |
| 列出路由 | |
| 添加路由 | |
| 删除路由 | |
curl -sf http://localhost:2019/config/ 2>/dev/nullbrew install caddycaddy startcurl -sf http://localhost:2019/config/ 2>/dev/nullbrew install caddycaddy startcurl -sf http://localhost:2019/config/apps/http/servers/local_proxies/routes 2>/dev/nullcurl -sf http://localhost:2019/config/apps/http/servers/local_proxies/routes 2>/dev/nullfor port in $(seq 3000 3100); do
lsof -i :$port > /dev/null 2>&1 || { echo $port; break; }
donecurl -sf http://localhost:2019/config/apps/http/servers/local_proxies > /dev/null 2>&1 || \
curl -sf -X POST http://localhost:2019/load \
-H "Content-Type: application/json" \
-d '{"apps":{"http":{"servers":{"local_proxies":{"listen":[":80"],"routes":[]}}}}}'curl -sf -X POST "http://localhost:2019/config/apps/http/servers/local_proxies/routes" \
-H "Content-Type: application/json" \
-d '{"@id":"proxy_NAME","match":[{"host":["NAME.localhost"]}],"handle":[{"handler":"reverse_proxy","upstreams":[{"dial":"localhost:PORT"}]}],"terminal":true}'for port in $(seq 3000 3100); do
lsof -i :$port > /dev/null 2>&1 || { echo $port; break; }
donecurl -sf http://localhost:2019/config/apps/http/servers/local_proxies > /dev/null 2>&1 || \
curl -sf -X POST http://localhost:2019/load \
-H "Content-Type: application/json" \
-d '{"apps":{"http":{"servers":{"local_proxies":{"listen":[":80"],"routes":[]}}}}}'curl -sf -X POST "http://localhost:2019/config/apps/http/servers/local_proxies/routes" \
-H "Content-Type: application/json" \
-d '{"@id":"proxy_NAME","match":[{"host":["NAME.localhost"]}],"handle":[{"handler":"reverse_proxy","upstreams":[{"dial":"localhost:PORT"}]}],"terminal":true}'curl -sf -X DELETE "http://localhost:2019/id/proxy_NAME"curl -sf -X DELETE "http://localhost:2019/id/proxy_NAME"{
"@id": "proxy_<name>",
"match": [{"host": ["<name>.localhost"]}],
"handle": [{"handler": "reverse_proxy", "upstreams": [{"dial": "localhost:<port>"}]}],
"terminal": true
}{
"@id": "proxy_<name>",
"match": [{"host": ["<name>.localhost"]}],
"handle": [{"handler": "reverse_proxy", "upstreams": [{"dial": "localhost:<port>"}]}],
"terminal": true
}| Error | Solution |
|---|---|
| Caddy not running | |
| Port 80 denied | |
| Route exists | Ask to update or pick different name |
| 错误 | 解决方案 |
|---|---|
| Caddy未运行 | |
| 80端口权限被拒绝 | |
| 路由已存在 | 询问用户是否更新或选择其他名称 |
*.localhost/etc/hosts*.localhost/etc/hosts