Hi. We have a trouble configuring Caddy. Please help!
Version: 0.10.4
I simplified config for the case.
We have 2 SPAs: main app and adm app. We want main app to open at dev.domain.net
and adm app to open at admin.dev.domain.net
Also we need main app to serve all paths to index.html
except some paths (in this snippet /user/
and /stat/
) which it should proxy and adm app to serve admin.html
(also some paths to proxy). Both index.html
and admin.html
lies in one root directory.
With this config it works correct except 404 error from the Caddy if i try to open some uri like admin.dev.domain.net/something
, but it should serve admin.html
. For the main app it works well.
I tried to change rewrite / admin.html
to
rewrite / {
to {path} {path}/ /
}
in the admin.dev.domain.net
block, but in this case Caddy serving index.html
at admin.dev.domain.net
instead of admin.html
! May be the index directive don’t work here?..
How to configure it properly?
So Caddyfile:
http://dev.domain.net, http://admin.dev.domain.net {
redir https://{host}{uri}
}
https://admin.dev.domain.net {
log /var/log/caddy/access_admin.log
errors /var/log/caddy/errors_admin.log
gzip
expires {
match \.js$ 1y
match \.png$ 1h
match core\.[a-f\d]\.css$ 1y
}
rewrite {
r ^/(user|stat)/(.*)$
to /{1}/{2}/
}
root /var/www/front/dev/dist
index admin.html
rewrite / admin.html
header / {
X-Frame-Options "DENY"
}
basicauth / user password
}
https://dev.domain.net {
log /var/log/caddy/access_main.log
errors /var/log/caddy/errors_main.log
gzip
expires {
match \.js$ 1y
match \.png$ 1h
match core\.[a-f\d]\.css$ 1y
}
rewrite {
r ^/(user|stat)/(.*)$
to /{1}/{2}/
}
root /var/www/front/dev/dist
index index.html
rewrite / {
if {path} match ^/sitemap\.html$
to {path} {path}/ /sitemap.html
}
rewrite / {
if {path} match ^/sitemap\.xml$
to {path} {path}/ /sitemap.xml
}
rewrite / {
to {path} {path}/ /
}
header / {
X-Frame-Options "DENY"
}
basicauth / user password
}
https://dev.domain.net/user/, https://admin.dev.domain.net/user/ {
log /var/log/caddy/access_user.log
errors /var/log/caddy/errors_user.log
gzip
proxy / http://127.0.0.1:3004 {
transparent
without user
}
cors / {
allowed_headers Auth-Token
}
}
https://dev.domain.net/stat/, https://admin.dev.domain.net/stat/ {
log /var/log/caddy/access_stat.log
errors /var/log/caddy/errors_stat.log
gzip
proxy / http://127.0.0.1:3005 {
transparent
without stat
}
cors / {
allowed_headers Auth-Token
}
}