Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A question about static file web page, Caddy only identify single web page named index.html? #5033

Closed
real-jiakai opened this issue Sep 11, 2022 · 10 comments
Labels
invalid ❓ This doesn't seem right

Comments

@real-jiakai
Copy link

This is my wrong Caddyfile config in /etc/caddy/Caddyfile

xxx.xxx.com {
        root * /var/www/bookmarks

        file_server {
                hide README.md
                index bookmarks.html
        }
}

When I change the name of bookmarks.html to index.html and modify the caddy config below. It works.

xxx.xxx.com {
        root * /var/www/bookmarks

        file_server
}

How to custom the entry html file instead of using the default html file named index.html?
I don't find content in the documentation. Looking forwaring to hearing from you soon.❤️❤️❤️
https://caddyserver.com/docs/caddyfile/directives/file_server

@mholt
Copy link
Member

mholt commented Sep 11, 2022

Thanks for opening an issue!

I can't reproduce the behavior, it works for me. So I'll need your help to understand it better.

Ideally, we need to be able to reproduce the bug in the most minimal way possible. This allows us to write regression tests to verify the fix is working. If we can't reproduce it, then you'll have to test our changes for us until it's fixed -- and then we can't add test cases, either.

I've attached a template below that will help make this easier and faster! This will require some effort on your part -- please understand that we will be dedicating time to fix the bug you are reporting if you can just help us understand it and reproduce it easily.

This template will ask for some information you've already provided; that's OK, just fill it out the best you can. 👍 I've also included some helpful tips below the template. Feel free to let me know if you have any questions!

Thank you again for your report, we look forward to resolving it!

Template

## 1. Environment

### 1a. Operating system and version

```
paste here
```


### 1b. Caddy version (run `caddy version` or paste commit SHA)

```
paste here
```


### 1c. Go version (if building Caddy from source; run `go version`)

```
paste here
```


## 2. Description

### 2a. What happens (briefly explain what is wrong)




### 2b. Why it's a bug (if it's not obvious)




### 2c. Log output

```
paste terminal output or logs here
```



### 2d. Workaround(s)




### 2e. Relevant links




## 3. Tutorial (minimal steps to reproduce the bug)




Instructions -- please heed otherwise we cannot help you (help us help you!)

  1. Environment: Please fill out your OS and Caddy versions, even if you don't think they are relevant. (They are always relevant.) If you built Caddy from source, provide the commit SHA and specify your exact Go version.

  2. Description: Describe at a high level what the bug is. What happens? Why is it a bug? Not all bugs are obvious, so convince readers that it's actually a bug.

    • 2c) Log output: Paste terminal output and/or complete logs in a code block. DO NOT REDACT INFORMATION except for credentials.
    • 2d) Workaround: What are you doing to work around the problem in the meantime? This can help others who encounter the same problem, until we implement a fix.
    • 2e) Relevant links: Please link to any related issues, pull requests, docs, and/or discussion. This can add crucial context to your report.
  3. Tutorial: What are the minimum required specific steps someone needs to take in order to experience the same bug? Your goal here is to make sure that anyone else can have the same experience with the bug as you do. You are writing a tutorial, so make sure to carry it out yourself before posting it. Please:

    • Start with an empty config. Add only the lines/parameters that are absolutely required to reproduce the bug.
    • Do not run Caddy inside containers.
    • Run Caddy manually in your terminal; do not use systemd or other init systems.
    • If making HTTP requests, avoid web browsers. Use a simpler HTTP client instead, like curl.
    • Do not redact any information from your config (except credentials). Domain names are public knowledge and often necessary for quick resolution of an issue!
    • Note that ignoring this advice may result in delays, or even in your issue being closed. 😞 Only actionable issues are kept open, and if there is not enough information or clarity to reproduce the bug, then the report is not actionable.

Example of a tutorial:

Create a config file:
{ ... }

Open terminal and run Caddy:

$ caddy ...

Make an HTTP request:

$ curl ...

Notice that the result is ___ but it should be ___.

@mholt mholt added the needs info 📭 Requires more information label Sep 11, 2022
@real-jiakai
Copy link
Author

real-jiakai commented Sep 11, 2022

1. Environment

1a. Operating system and version

[root@iZnyxyx6w93gkwZ ~]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.9.2009 (Core)
Release:        7.9.2009
Codename:       Core

1b. Caddy version (run caddy version or paste commit SHA)

[root@iZnyxyx6w93gkwZ ~]# caddy version
v2.5.2 h1:eCJdLyEyAGzuQTa5Mh3gETnYWDClo1LjtQm2q9RNZrs=

1c. Go version (if building Caddy from source; run go version)

# nothing. I install the caddy by paste the following comands in caddy documentation website below:
# https://caddyserver.com/docs/install#fedora-redhat-centos
yum install yum-plugin-copr
yum copr enable @caddy/caddy
yum install caddy

2. Description

2a. What happens (briefly explain what is wrong)

I put a single html file named bookmarks.html in directory /var/www/bookmarks and add some config in Caddyfile in directory /etc/caddy/Caddyfile. The config is below.

bookmark.xxx.com {
    root * /var/www/bookmarks
   
    file_server
}

Then I reload the caddy server by command systemctl reload caddy. When I input the domain name in my chrome browser bookmarks.xxx.com and get the http 404 error. So I look up the documention in caddy about static files. I modified the Caddyfile below:

bookmark.xxx.com {
    root * /var/www/bookmarks
   
    file_server {
        index bookmarks.html
    }
}

the index option doesn't work.

index is a list of filenames to look for as index files. Default: index.html index.txt

I think that caddy will take bookmarks.html as the entry html file instead of index.html file after I add this option. But it doesn't work.

Finally. I change the single html file name bookmarks.html to index.html and recover the Caddyfile config below:

bookmark.xxx.com {
    root * /var/www/bookmarks
   
    file_server
}

After reloading, caddy works for me.

I search for a lone time in google and issues in github. But I didn't find my favoured answer about this. I want to ask that Does caddy support customing the static html file name instead of using the default name index.html

Looking forward to hearing from you.❤️❤️❤️

2b. Why it's a bug (if it's not obvious)

I don't know about this. I want to ask that does caddy support customing the static html file name instead of using the default name index.html

2c. Log output

I restore the situation just now. journalctl -u caddy log is below. But I think there is no special point to solve my doubt.

Sep 11 12:42:07 iZnyxyx6w93gkwZ systemd[1]: Reloading Caddy.
Sep 11 12:42:07 iZnyxyx6w93gkwZ caddy[26538]: {"level":"info","ts":1662871327.6214411,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":""}
Sep 11 12:42:07 iZnyxyx6w93gkwZ caddy[26538]: {"level":"warn","ts":1662871327.624404,"msg":"Caddyfile input is not formatted; run the 'caddy fmt' command to fix inconsistencies","adapter":"caddyfile","file":"/etc/caddy/Caddyfile"Sep 11 12:42:07 iZnyxyx6w93gkwZ caddy[26538]: {"level":"info","ts":1662871327.624443,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":""}
Sep 11 12:42:07 iZnyxyx6w93gkwZ caddy[26538]: {"level":"warn","ts":1662871327.6252224,"msg":"Caddyfile input is not formatted; run the 'caddy fmt' command to fix inconsistencies","adapter":"caddyfile","file":"/etc/caddy/CaddyfileSep 11 12:42:07 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662871327.62817,"logger":"admin.api","msg":"received request","method":"POST","host":"localhost:2019","uri":"/load","remote_ip":"127.0.0.1","remote_port":"33792"Sep 11 12:42:07 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662871327.6286213,"logger":"admin","msg":"admin endpoint started","address":"tcp/localhost:2019","enforce_origin":false,"origins":["//[::1]:2019","//127.0.0.1:20Sep 11 12:42:07 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662871327.6287322,"logger":"http","msg":"server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS","server_name":"Sep 11 12:42:07 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662871327.6287441,"logger":"http","msg":"enabling automatic HTTP->HTTPS redirects","server_name":"srv0"}
Sep 11 12:42:07 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662871327.628972,"logger":"http","msg":"enabling automatic TLS certificate management","domains":["bookmark.gujiakai.top","proxy.gujiakai.top"]}
Sep 11 12:42:07 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662871327.6319034,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc000426850"}
Sep 11 12:42:07 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662871327.6352236,"logger":"tls.cache.maintenance","msg":"stopped background certificate maintenance","cache":"0xc0005c7030"}
Sep 11 12:42:07 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662871327.6353588,"msg":"autosaved config (load with --resume flag)","file":"/var/lib/caddy/.config/caddy/autosave.json"}
Sep 11 12:42:07 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662871327.6354043,"logger":"admin.api","msg":"load complete"}
Sep 11 12:42:07 iZnyxyx6w93gkwZ systemd[1]: Reloaded Caddy.
Sep 11 12:42:07 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662871327.6431975,"logger":"admin","msg":"stopped previous server","address":"tcp/localhost:2019"}
Sep 11 12:55:22 iZnyxyx6w93gkwZ systemd[1]: Reloading Caddy.
Sep 11 12:55:22 iZnyxyx6w93gkwZ caddy[26826]: {"level":"info","ts":1662872122.0345628,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":""}
Sep 11 12:55:22 iZnyxyx6w93gkwZ caddy[26826]: {"level":"warn","ts":1662872122.0373528,"msg":"Caddyfile input is not formatted; run the 'caddy fmt' command to fix inconsistencies","adapter":"caddyfile","file":"/etc/caddy/CaddyfileSep 11 12:55:22 iZnyxyx6w93gkwZ caddy[26826]: {"level":"info","ts":1662872122.037384,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":""}
Sep 11 12:55:22 iZnyxyx6w93gkwZ caddy[26826]: {"level":"warn","ts":1662872122.0380812,"msg":"Caddyfile input is not formatted; run the 'caddy fmt' command to fix inconsistencies","adapter":"caddyfile","file":"/etc/caddy/CaddyfileSep 11 12:55:22 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662872122.0408828,"logger":"admin.api","msg":"received request","method":"POST","host":"localhost:2019","uri":"/load","remote_ip":"127.0.0.1","remote_port":"3729Sep 11 12:55:22 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662872122.0413327,"logger":"admin","msg":"admin endpoint started","address":"tcp/localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:20Sep 11 12:55:22 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662872122.0414367,"logger":"http","msg":"server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS","server_name":"Sep 11 12:55:22 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662872122.0414498,"logger":"http","msg":"enabling automatic HTTP->HTTPS redirects","server_name":"srv0"}
Sep 11 12:55:22 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662872122.0416381,"logger":"http","msg":"enabling automatic TLS certificate management","domains":["bookmark.gujiakai.top","proxy.gujiakai.top"]}
Sep 11 12:55:22 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662872122.0442252,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc000426fc0"}
Sep 11 12:55:22 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662872122.0465043,"logger":"tls.cache.maintenance","msg":"stopped background certificate maintenance","cache":"0xc000426850"}
Sep 11 12:55:22 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662872122.0466049,"msg":"autosaved config (load with --resume flag)","file":"/var/lib/caddy/.config/caddy/autosave.json"}
Sep 11 12:55:22 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662872122.0466394,"logger":"admin.api","msg":"load complete"}
Sep 11 12:55:22 iZnyxyx6w93gkwZ systemd[1]: Reloaded Caddy.
Sep 11 12:55:22 iZnyxyx6w93gkwZ caddy[22432]: {"level":"info","ts":1662872122.0536356,"logger":"admin","msg":"stopped previous server","address":"tcp/localhost:2019"}

2d. Workaround(s)

Currently, I solve this problem by changing the single html file name to index.html. I want to ask that does caddy support customing the static html file name instead of using the default name index.html

2e. Relevant links

caddy static files
caddy file_server

3. Tutorial (minimal steps to reproduce the bug)

  • put a single html file named bookmarks.html in /var/www directory.
  • modify the Caddyfile in /etc/caddy directory
  • add config below
bookmark.xxx.com {
    root * /var/www/bookmarks
   
    file_server
}
  • input bookmarks.xxx.com in web browser and get http 404 error
  • change the filename to index.html
  • reload the caddy by command systemctl reload caddy
  • the problem is solved.

@mholt
Copy link
Member

mholt commented Sep 11, 2022

Thanks for the details! It still works for me...

What is the output of ls -la /var/www? (With the bookmarks file there)

And what are your logs if you enable debug mode?

{
    debug
}

And also please enable access logs, just put the log directive in your site block.

And can you show a curl -v request that has the problem? Thank you!

@real-jiakai
Copy link
Author

In my case. I put the bookmarks.html in /var/www/bookmarks directory.

[root@iZnyxyx6w93gkwZ bookmarks]# ls -la /var/www
total 12
drwxr-xr-x   3 root root 4096 Sep 11 13:47 .
drwxr-xr-x. 20 root root 4096 Sep 11 09:29 ..
drwxr-xr-x   3 root root 4096 Sep 11 13:47 bookmarks
[root@iZnyxyx6w93gkwZ bookmarks]# ls -la /var/www/bookmarks/
total 388
drwxr-xr-x 3 root root   4096 Sep 11 13:47 .
drwxr-xr-x 3 root root   4096 Sep 11 13:47 ..
-rw-r--r-- 1 root root 376858 Sep 11 09:34 bookmarks.html
drwxr-xr-x 8 root root   4096 Sep 11 09:34 .git
-rw-r--r-- 1 root root     68 Sep 11 09:34 .gitignore

I have added some extra config in /etc/caddy/Caddyfile below:

{
        debug
        log {
                output file /var/log/access.log
        }
}

bookmark.xxx.com {
        root * /var/www/bookmarks

        file_server
}

when I input the commandsystemctl status caddy -l. It shows logs below.

Sep 11 13:53:02 iZnyxyx6w93gkwZ systemd[1]: Reload failed for Caddy.
Sep 11 13:56:10 iZnyxyx6w93gkwZ caddy[22432]: {"level":"debug","ts":1662875770.9071977,"logger":"tls.handshake","msg":"choosing certificate","identifier":"bookmark.gujiakai.top","num_choices":1}
Sep 11 13:56:10 iZnyxyx6w93gkwZ caddy[22432]: {"level":"debug","ts":1662875770.9072394,"logger":"tls.handshake","msg":"default certificate selection results","identifier":"bookmark.gujiakai.top","subjects":["bookmark.gujiakai.top"],"managed":true,"issuer_key":"acme-v02.api.letsencrypt.org-directory","hash":"cbe4f1640d7248bc6a1ceeea161a1f4fd1cd1f753023062e0ebd3041143687f1"}
Sep 11 13:56:10 iZnyxyx6w93gkwZ caddy[22432]: {"level":"debug","ts":1662875770.907261,"logger":"tls.handshake","msg":"matched certificate in cache","subjects":["bookmark.gujiakai.top"],"managed":true,"expiration":1670629669,"hash":"cbe4f1640d7248bc6a1ceeea161a1f4fd1cd1f753023062e0ebd3041143687f1"}
Sep 11 13:56:10 iZnyxyx6w93gkwZ caddy[22432]: {"level":"debug","ts":1662875770.9361696,"logger":"http.handlers.file_server","msg":"sanitized path join","site_root":"/var/www/bookmarks","request_path":"/","result":"/var/www/bookmarks"}
Sep 11 13:56:10 iZnyxyx6w93gkwZ caddy[22432]: {"level":"debug","ts":1662875770.936202,"logger":"http.handlers.file_server","msg":"no index file in directory","path":"/var/www/bookmarks","index_filenames":["index.html","index.txt"]}
Sep 11 13:56:10 iZnyxyx6w93gkwZ caddy[22432]: {"level":"debug","ts":1662875770.9362402,"logger":"http.log.error","msg":"{id=s5g0eyk5s} fileserver.(*FileServer).notFound (staticfiles.go:511): HTTP 404","request":{"remote_ip":"36.152.114.136","remote_port":"31450","proto":"HTTP/2.0","method":"GET","host":"bookmark.gujiakai.top","uri":"/","headers":{"Sec-Ch-Ua-Mobile":["?0"],"Sec-Fetch-Site":["none"],"Sec-Fetch-User":["?1"],"Accept-Encoding":["gzip, deflate, br"],"Accept-Language":["zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"],"Sec-Fetch-Dest":["document"],"Cache-Control":["max-age=0"],"Sec-Ch-Ua-Platform":["\"Windows\""],"Dnt":["1"],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-Mode":["navigate"],"Sec-Ch-Ua":["\"Google Chrome\";v=\"105\", \"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"105\""],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"bookmark.gujiakai.top"}},"duration":0.000110435,"status":404,"err_id":"s5g0eyk5s","err_trace":"fileserver.(*FileServer).notFound (staticfiles.go:511)"}
Sep 11 13:56:12 iZnyxyx6w93gkwZ caddy[22432]: {"level":"debug","ts":1662875772.7877145,"logger":"http.handlers.file_server","msg":"sanitized path join","site_root":"/var/www/bookmarks","request_path":"/","result":"/var/www/bookmarks"}
Sep 11 13:56:12 iZnyxyx6w93gkwZ caddy[22432]: {"level":"debug","ts":1662875772.7877595,"logger":"http.handlers.file_server","msg":"no index file in directory","path":"/var/www/bookmarks","index_filenames":["index.html","index.txt"]}
Sep 11 13:56:12 iZnyxyx6w93gkwZ caddy[22432]: {"level":"debug","ts":1662875772.7877986,"logger":"http.log.error","msg":"{id=d5nri8rdg} fileserver.(*FileServer).notFound (staticfiles.go:511): HTTP 404","request":{"remote_ip":"36.152.114.136","remote_port":"31450","proto":"HTTP/2.0","method":"GET","host":"bookmark.gujiakai.top","uri":"/","headers":{"Sec-Ch-Ua-Mobile":["?0"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"],"Sec-Fetch-Mode":["navigate"],"Accept-Language":["zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"],"Cache-Control":["max-age=0"],"Sec-Ch-Ua-Platform":["\"Windows\""],"Upgrade-Insecure-Requests":["1"],"Sec-Ch-Ua":["\"Google Chrome\";v=\"105\", \"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"105\""],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"],"Sec-Fetch-Site":["none"],"Sec-Fetch-User":["?1"],"Dnt":["1"],"Sec-Fetch-Dest":["document"],"Accept-Encoding":["gzip, deflate, br"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"bookmark.gujiakai.top"}},"duration":0.000134092,"status":404,"err_id":"d5nri8rdg","err_trace":"fileserver.(*FileServer).notFound (staticfiles.go:511)"}

The key error msg is below.

Sep 11 13:56:12 iZnyxyx6w93gkwZ caddy[22432]: {"level":"debug","ts":1662875772.7877595,"logger":"http.handlers.file_server","msg":"no index file in directory","path":"/var/www/bookmarks","index_filenames":["index.html","index.txt"]}

It shows that there is no index file in /var/www/bookmarksdirectory. But there is a html file named bookmarks.html in /var/www/bookmarks directory. The tips in the end "index_filenames":["index.html","index.txt"] seems imply that I can custom the index_filenams. But I only find the index option in file_server guide. And it doesn't works for me.

I modify the Caddyfile config below and input the command systemctl start caddy to start the caddy server.

{
    debug
    log{
        output file /var/log/access.log
    }
}

bookmark.xxx.com {
    root * /var/www/bookmarks
   
    file_server {
        index bookmarks.html
    }
}

But it still didn't work for me as index option can't change the index_filenames list.

The result of curl -v my site is below:

[root@iZnyxyx6w93gkwZ caddy]# curl -v bookmark.gujiakai.top
* About to connect() to bookmark.gujiakai.top port 80 (#0)
*   Trying 47.102.145.217...
* Connected to bookmark.gujiakai.top (47.102.145.217) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: bookmark.gujiakai.top
> Accept: */*
> 
< HTTP/1.1 308 Permanent Redirect
< Connection: close
< Location: https://bookmark.gujiakai.top/
< Server: Caddy
< Date: Sun, 11 Sep 2022 06:14:57 GMT
< Content-Length: 0
< 
* Closing connection 0

In fact. As long as I can change the index_filenames list. The issue can be solved. Can you have any good tips?
Looking forward to hearing from you.❤️❤️❤️

@francislavoie
Copy link
Member

drwxr-xr-x 8 root root 4096 Sep 11 09:34 .git

Btw, keep in mind that you'll need to hide .git otherwise your entire git repo will be downloadable (with difficulty if you don't have browse enabled, but it could get crawled)

@real-jiakai
Copy link
Author

drwxr-xr-x 8 root root 4096 Sep 11 09:34 .gitDrwxr-xr-x8根4096 Sep 1109:34. git

Btw, keep in mind that you'll need to hide .git otherwise your entire git repo will be downloadable (with difficulty if you don't have browse enabled, but it could get crawled)

Ok. I have added the hide option. I find that when I input the domain name https://bookmark.xxx.com/bookmarks.html.
It works for me. How should I modify the Caddyfile to change the entry html file. I need bookmarks.html as my entry instead of index.html though I can solve this issue by changing the file name.

Looking forward to hearing from you.❤️❤️❤️

{
        debug
        log {
                output file /var/log/access.log
        }
}

bookmark.xxx.xxx {
        root * /var/www/bookmarks

        file_server {
                hide .git
                index bookmarks.html
        }
}

@francislavoie
Copy link
Member

Yeah I understand that doesn't solve your problem - I'm not at my computer currently, I'm on vacation so I'm just reading this from my phone, just wanted to point out that point about git. I hope Matt can figure out the problem 😅

@mholt
Copy link
Member

mholt commented Sep 12, 2022

@real-jiakai

Sep 11 13:53:02 iZnyxyx6w93gkwZ systemd[1]: Reload failed for Caddy.

Caddy isn't even seeing the updated config. Presumably it doesn't even know about your custom index filename. What's the error before that log?

@real-jiakai
Copy link
Author

real-jiakai commented Sep 13, 2022

[root@iZnyxyx6w93gkwZ bookmarks]# ls
bookmarks.html
[root@iZnyxyx6w93gkwZ bookmarks]# pwd
/var/www/bookmarks
[root@iZnyxyx6w93gkwZ bookmarks]# cat /etc/caddy/Caddyfile 
# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.

bookmark.gujiakai.top {
        root * /var/www/bookmarks

        file_server {
                hide .git
                index bookmarks.html
        }
}

# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile

Now, it works. demo website. I don't figure out why didn't it take effect a few days ago. Maybe When I ran caddy fmt command. I didn't add the --overwrite option. This led to the Caddyfile not work. I'm a caddy beginner. I need to read documentation more. Thank you for your help.❤️❤️❤️❤️❤️

@mholt
Copy link
Member

mholt commented Sep 13, 2022

There was likely a syntax error in your Caddyfile so the command to apply changes didn't succeed. Always check for errors! Glad you got it working.

@mholt mholt closed this as completed Sep 13, 2022
@mholt mholt added invalid ❓ This doesn't seem right and removed needs info 📭 Requires more information labels Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid ❓ This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants