From 7b2489a8663450dc07bfa2fcad85f2c8c2abf692 Mon Sep 17 00:00:00 2001 From: bob Date: Fri, 6 Jan 2023 15:45:44 +0800 Subject: [PATCH] fix(doc) caddy config --- _compose/caddy/conf/Caddyfile | 36 ++++++++++++++++++++--------------- _doc/caddy.md | 4 ++++ 2 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 _doc/caddy.md diff --git a/_compose/caddy/conf/Caddyfile b/_compose/caddy/conf/Caddyfile index d59003d..e09830e 100644 --- a/_compose/caddy/conf/Caddyfile +++ b/_compose/caddy/conf/Caddyfile @@ -1,23 +1,29 @@ -:8300, localhost { +(CORS) { + @origin header Origin {args.0} + header @origin Access-Control-Allow-Origin "{args.0}" + header @origin Access-Control-Allow-Methods "OPTIONS,HEAD,GET,POST,PUT,PATCH,DELETE" +} - root * /data/dist - # Vue Router history模式,避免刷新后404页面;字符中间不可有空格 - try_files {path} /index.html +:8300 { +encode zstd gzip handle_path /stage-api/* { - + import CORS uri strip_prefix /stage-api # 需要代理到的IP以及端口号 reverse_proxy ruoyi-admin:8080 } - file_server - encode zstd gzip - # CORS - import CORS -} + handle { + root * /data/dist + # Vue Router history模式,避免刷新后404页面;字符中间不可有空格 + try_files {path}.html {path} /index.html + file_server + } + + log { + format formatted "[{ts}] {request>remote_addr} {request>proto} {request>method} <- {status} -> {request>host} {request>uri} {request>headers>User-Agent>[0]}" { + time_format "iso8601" + } + output file "/dev/stdout" + } -(CORS) { - header replace Access-Control-Allow-Origin "*" - header replace Access-Control-Allow-Headers "*" - header replace Access-Control-Allow-Methods "*" - header replace Access-Control-Request-Method "POST, GET, OPTIONS" } \ No newline at end of file diff --git a/_doc/caddy.md b/_doc/caddy.md new file mode 100644 index 0000000..dafcd4d --- /dev/null +++ b/_doc/caddy.md @@ -0,0 +1,4 @@ + + +handle_path /stage-api/,handle配置顺序说明 +https://caddy.community/t/caddy-with-vue-router/12352/2 \ No newline at end of file