You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Nginx配置中无需使用带点前缀的隐藏路径映射assetlinks.json

实现方案

你可以通过以下两种Nginx配置方式实现需求,无需创建.well-known隐藏目录:

使用精确匹配的location结合alias直接指向目标文件,性能最优且不会影响其他.well-known路径的请求:

location = /.well-known/assetlinks.json {
    alias /var/www/static/google-association-service/assetlinks.json;
    types { } default_type "application/json";
}

你只需要把assetlinks.json文件直接放在/var/www/static/google-association-service/目录下即可正常访问。

方案2:批量适配所有.well-known路径请求

如果你后续还有其他谷歌要求的.well-known目录下的文件需要部署,可以用rewrite规则批量处理,所有.well-known下的请求都会直接映射到目标目录下的对应文件:

location ~ ^/\.well-known/(.*)$ {
    root /var/www/static/google-association-service/;
    rewrite ^/\.well-known/(.*)$ /$1 break;
    types { } default_type "application/json";
}

注意事项

  • 方案1的=号必须保留,用于精确匹配指定URI,避免被其他前缀location规则拦截
  • 不要删除default_type配置,否则可能返回错误的Content-Type头导致谷歌关联验证失败

内容的提问来源于stack exchange,提问作者Travis Griggs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 13:18:06