Unwanted redirection of index.html file

(Jean-Luc Lacroix) #1

I have set up a simple server on my a test server on my LAN with the following config:

ursule:81 {
	tls off
	root /var/www
	errors /var/log/caddy/error.log
	log /var/log/caddy/access.log
	fastcgi  /var/run/php5-fpm.sock php 

No smartUrl, no Index and no Redirection directives. In the root I have a index.html and a index.php file. When I request the index.html I get redirected to the index.php file.

$ curl -LI  ursule:81/index.html
HTTP/1.1 301 Moved Permanently
Location: /
Server: Caddy
Date: Thu, 11 Jan 2018 06:02:40 GMT
Content-Type: text/plain; charset=utf-8

HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Server: Caddy
Date: Thu, 11 Jan 2018 06:02:40 GMT

In the caddy access.log: - - [11/Jan/2018:07:02:40 +0100] "HEAD /index.html HTTP/1.1" 301 0 - - [11/Jan/2018:07:02:40 +0100] "HEAD / HTTP/1.1" 200 0

No entry in caddy error.log

In syslog:

Jan 11 07:02:40 ursule caddy[2502]: 2018/01/11 07:02:40 [INFO] localhost - No such site at :81 (Remote: ::1, Referer: )

Furthermore, when the http request points to the document root /, Caddy serves index.php instead of index.html (not a redirection). According to the http.index doc, the default (implicit) file that should be served in that case is, index.html.

Is this the expected behavior or should I file an issue on GitHub?

(Matt Holt) #2

You’ve defined the hostname to be ursule but you apparently accessed it via localhost so Caddy doesn’t know which site to respond with. You’ll have to use the same hostname to access that site.

(Jean-Luc Lacroix) #3

I access the test server from another host on the LAN. The Caddy server IP is resolved by a local DNS (dnsmask).

To make sure, I changed the Caddyfile to the actual server IP and observed the same behavior when accessed with its real IP instead of local hostname ursule. No change. Same log entries than above.

(Matthew Fay) #4

The redirect from /index.html to / is a standard, canonical redirect given by Caddy’s static file server, which handles the first request.

The reason you’re getting index.php over index.html on the second request is because your fastcgi directive is configured to, as a blanket rule, proxy all requests to the PHP-FPM socket. The php preset defines index.php as the index file for this type of request.

Because you’ve configured Caddy to do this, it doesn’t need to serve files off the disk directly, and never refers to the http.index priority list at all.

To get the behaviour you want (serving index.html for requests to /), remove the fastcgi directive.

(Jean-Luc Lacroix) #5

Not a big deal anyway, I will just have to remember not to put a index.html and a index.php in the same dir to avoid confusion. Thanks for your clear explanation.