Review what I actually done that night:
-
Deploy Wordpress & v2ray on caddy V1, I bind two domains on one site. Then I decided to upgrade to caddy V2.
-
Deploy on caddyV2 with a brand new Caddyfile, I test the redirection on domain A, everything works.
-
Try to deploy v2ray & websocket, because there is no any example for V2, I use V1 config and fix all config parse errors by remove lines. At that time, Caddyfile should be:
(php) {
encode zstd gzip
php_fastcgi 127.0.0.1:9000
try_files {path} {path}/index.php /index.php?{query}
file_server
}
zhangshenjia.com
{
root * /www/zhanshenjia.com
reverse_proxy /gg localhost:10000
import php
}
shenjia.de
{
root * /www/zhangshenjia.com
reverse_proxy /gg localhost:10000
import php
}
-
I found the direction works on domain A (zhangshenjia.com), but not work on domain B (shenjia.de). I checked Caddyfile and make sure the part of them were exactly same!
-
I tried to debug Caddyfile line by line, but domain A keep working, domain B keep failing. I tried Chrome Incognito mode and found out that direction failed on both domain A & B. I got completely confused.
My browser cached the 301 redirection on domain A I visited before I migrated config from V1, that’s what I figured out next day.
- A hour later, I’m so exhausted that I wrote this post at 3:00 AM, then go to sleep. I remove this line below because it looks useless in test, that’s my fault.
try_files {path} {path}/index.php /index.php?{query}
- Next morning, I saw your reply, and tried to deploy a brand new site on another VPS, and found out that direction works with basic config. Inspire of you, I use
curl -v
to test direction instead of browser, and finally figure out everything works without that single line and browser cache.
And the lesson is : NEVER test redirection with browser cache. BTW, I think the feature (automatically add trailing slash on directory) should be mentioned in documents.
THX for your time and inspiration!