This issue created from here: https://caddy.community/t/caddy-serves-index-html-instead-of-admin-html-or-spa-dont-work-on-non-root-urls/2445/8
caddy -version)?0.10.6
I'm trying to serve different index files at different sites configuring caddy for two SPA apps in one root dir.
Here "domain" is a placeholder, not a real domain.
My example from forum:
https://admin.dev.domain.net {
root /var/www/front/dev/dist
index admin.html
rewrite / admin.html
}
https://dev.domain.net {
root /var/www/front/dev/dist
index index.html
rewrite {
to {path} {path}/ /
}
}
root@dev ~/ $ cat /etc/init/caddy.conf
description "Caddy Server startup script"
start on runlevel [2345]
stop on runlevel [016]
respawn
respawn limit 10 5
script
cd /etc/caddy
exec /usr/local/bin/caddy
end script
Files:
root@dev ~/ $ cat /var/www/front/dev/dist/admin.html
admin ok
root@dev ~/ $ cat /var/www/front/dev/dist/index.html
index ok
Requests:
felian@felian-VirtualBox:~/$ curl -i dev.domain.net
HTTP/1.1 301 Moved Permanently
Connection: close
Location: https://dev.domain.net/
Server: Caddy
Date: Wed, 02 Aug 2017 06:34:21 GMT
Content-Length: 59
Content-Type: text/html; charset=utf-8
<a href="https://dev.domain.net/">Moved Permanently</a>.
felian@felian-VirtualBox:~/$ curl -i admin.dev.domain.net
HTTP/1.1 301 Moved Permanently
Connection: close
Location: https://admin.dev.domain.net/
Server: Caddy
Date: Wed, 02 Aug 2017 06:34:25 GMT
Content-Length: 65
Content-Type: text/html; charset=utf-8
<a href="https://admin.dev.domain.net/">Moved Permanently</a>.
felian@felian-VirtualBox:~/$ curl -L dev.domain.net
index ok
felian@felian-VirtualBox:~/$ curl -L dev.domain.net/g
index ok
felian@felian-VirtualBox:~/$ curl -L admin.dev.domain.net
admin ok
felian@felian-VirtualBox:~/$ curl -L admin.dev.domain.net/g
404 Not Found
We want the last request to result with admin.html, not 404.
Also tried this config with
rewrite {
to {path} {path}/ /
}
instead of rewrite / admin.html in dev.admin.domain.net block. It leads last 4 curl requests to return index ok:
felian@felian-VirtualBox:~/$ curl -L dev.domain.net
index ok
felian@felian-VirtualBox:~/$ curl -L dev.domain.net/g
index ok
felian@felian-VirtualBox:~/$ curl -L admin.dev.domain.net
index ok
felian@felian-VirtualBox:~/$ curl -L admin.dev.domain.net/g
index ok
felian@felian-VirtualBox:~/$ curl -L admin.dev.domain.net/admin/
index ok
Listing of /var/www/front/dev/dist (root in config) directory :
root@dev ~/ $ ls /var/www/front/dev/dist/
admin.html b.app.a2f0e111.js b.game1.a4f18f87.js b.game2.cb680127.js sitemap.html
b.game3.2896ea39.js b.core.87f10c2d.js b.game4.d85919a0.js favicon.ico static
b.admin.266f034f.js b.game5.6c582e87.js b.game6.b0b57c63.js index.html
We need: admin.dev.domain.net returns admin.html for / path and admin.html for other paths.
1 Code:
index admin.html
rewrite {
to {path} {path}/ /
}
Results to: admin.dev.domain.net returns always index.html instead of admin.html from this block (seen in logs).
2 Code:
index admin.html
rewrite / admin.html
Results to: admin.dev.domain.net returns admin.html for / path and 404 for other paths.
3 Code:
index admin.html
rewrite {
to {path} {path}/ /admin.html
}
Results to: admin.dev.domain.net returns index.html for / path and admin.html for other paths.
It is unclear. More information you can get from out topic in the forum: https://caddy.community/t/caddy-serves-index-html-instead-of-admin-html-or-spa-dont-work-on-non-root-urls/2445/8
Hello @mtfelian,
thank you for your time! Yes, index directive does not work per-site and the documentation is unclear!
We have two options :
index usage as a feature request" (perfect challenge for Go newbies ) ping @mholt
It is a feature request. I think per-site index is a good thing.
Most helpful comment
Hello @mtfelian,
thank you for your time! Yes,
indexdirective does not work per-site and the documentation is unclear!We have two options :
indexusage as a feature request" (perfect challenge for Go newbies )ping @mholt