caddyhttp/index: Improve Documentation / Per-Site Index

Created on 2 Aug 2017  路  2Comments  路  Source: caddyserver/caddy

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

1. What version of Caddy are you using (caddy -version)?

0.10.6

2. What are you trying to do?

I'm trying to serve different index files at different sites configuring caddy for two SPA apps in one root dir.

3. What is your entire Caddyfile?

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}/ /
  }
}

4. How did you run Caddy (give the full command and describe the execution environment)?

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

5. Please paste any relevant HTTP request(s) here.

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

6. What did you expect to see?

We need: admin.dev.domain.net returns admin.html for / path and admin.html for other paths.

7. What did you see instead (give full error messages and/or log)?

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.

8. How can someone who is starting from scratch reproduce the bug as minimally as possible?

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

documentation feature request

Most helpful comment

Hello @mtfelian,

thank you for your time! Yes, index directive does not work per-site and the documentation is unclear!

We have two options :

  1. "Improve the documentation"
  2. "Implement per-site index usage as a feature request" (perfect challenge for Go newbies )

ping @mholt

All 2 comments

Hello @mtfelian,

thank you for your time! Yes, index directive does not work per-site and the documentation is unclear!

We have two options :

  1. "Improve the documentation"
  2. "Implement per-site 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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PhilmacFLy picture PhilmacFLy  路  3Comments

crvv picture crvv  路  3Comments

treviser picture treviser  路  3Comments

lorddaedra picture lorddaedra  路  3Comments

klaasel picture klaasel  路  3Comments