V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
EXChen
V2EX  ›  问与答

关于 Caddy 配置的问题

  •  
  •   EXChen · 2020-01-14 20:42:43 +08:00 · 2185 次点击
    这是一个创建于 1535 天前的主题,其中的信息可能已经有所发展或是发生改变。

    场景:我的博客接入了 Google AdSense,但是我没有在根域名下面放入“ads.txt” 文件,我真实放置的位置是在“www”子域名下,根域名使用了 Caddy 做 301 跳转,访问根域名地址会跳转到“www”子域名下面。

    问题:如何使用 Caddy 访问“https://xxx.cn/ads.txt”地址看到的内容是“https://www.xxx.cn/ads.txt” 地址下面的内容,并且浏览器上面的网址依然是“https://xxx.cn/ads.txt”?

    5 条回复    2020-01-15 11:54:48 +08:00
    loy6491
        1
    loy6491  
       2020-01-14 20:51:03 +08:00
    使用 Chrome 浏览器
    Buges
        2
    Buges  
       2020-01-14 20:54:29 +08:00
    msg7086
        3
    msg7086  
       2020-01-14 20:55:19 +08:00 via Android
    把跳转改成转发?
    also24
        4
    also24  
       2020-01-14 21:04:54 +08:00
    首先,建议把 xxx.cn 称呼为 “裸域” 而不是 “根域名”,“根域名” 一般指的是 “.”

    没有太折腾过 caddy,翻看了一下文档,按你的想法应该可以这样配置:
    xxx.cn{
    proxy /ads.txt www.xxx.cn
    }

    当然我感觉你应该把问题考虑复杂了,这事儿应该和 www.xxx.cn 没什么关系,应该只需要
    xxx.cn/ads.txt {
    root /data/wwwroot/www.xxx.cn
    }
    EXChen
        5
    EXChen  
    OP
       2020-01-15 11:54:48 +08:00
    ads.txt 支持托管在子域上面。

    Google 支持单一 HTTP 重定向至原始根网域外的目标(例如 example1.com/ads.txt 重定向至 example2.com/ads.txt )。请参阅 IAB 更新。

    Google 也支持多个重定向,前提是每个重定向位置都保留在原始根网域内。例如:

    example.com/ads.txt 重定向到 www.example.com/ads.txt
    example.com/ads.txt 重定向到 subdomain.example.com/ads.txt
    example.com/ads.txt 重定向到 example.com/page/ads.txt
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1138 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 18:38 · PVG 02:38 · LAX 11:38 · JFK 14:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.