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

AWS环境下sharing.sample.app子域名Apple App Site Association文件配置问题

问题分析与解决方案

问题场景

  • 在AWS Route 53配置了无别名、简单路由策略的A记录子域名sharing.sample.app,指向Ubuntu服务器;主域名sample.app托管在S3。
  • 将apple-app-site-association文件上传至Ubuntu服务器的/var/www/html/sharing目录后,访问sharing.sample.app/apple-app-site-association会自动跳转至sharing.sample.app根路径。
  • 主域名S3根目录上传该文件后可正常下载,通过AASA验证工具检测得到以下结果:
    • ✅ 域名有效(DNS验证通过)
    • ✅ 文件通过HTTPS提供
    • ❌ 服务器返回错误状态码(>=400)
    • ⚠️ 未定义content-type请求头
    • ⚠️ 文件需包含有效JSON(未运行JSON测试)

解决步骤

1. 修复访问跳转问题

跳转由Web服务器(Nginx/Apache)的规则配置导致,需针对性调整:

若使用Nginx:

  • 打开子域名对应的配置文件(通常在/etc/nginx/sites-available/或/etc/nginx/conf.d/目录下)
  • 添加精准匹配apple-app-site-association的规则,避免被其他跳转逻辑覆盖:
server {
    listen 443 ssl;
    server_name sharing.sample.app;
    root /var/www/html/sharing;

    # 直接匹配目标文件,禁止跳转
    location = /apple-app-site-association {
        try_files $uri =404;
        default_type application/json; # 提前设置合规的Content-Type
    }

    # 保留原有根路径规则
    location / {
        try_files $uri $uri/ =404;
    }

    # 你的SSL配置(省略)
}
  • 重启Nginx服务:sudo systemctl restart nginx

若使用Apache:

  • 打开子域名的虚拟主机配置文件(通常在/etc/apache2/sites-available/目录下)
  • 添加针对目标文件的规则,屏蔽跳转逻辑并设置请求头:
<VirtualHost *:443>
    ServerName sharing.sample.app
    DocumentRoot /var/www/html/sharing

    <Files "apple-app-site-association">
        Header set Content-Type application/json
        Allow from all
        Require all granted
    </Files>

    # 你的SSL配置(省略)
</VirtualHost>
  • 重启Apache服务:sudo systemctl restart apache2

2. 修复状态码与文件合规性问题

  • 确认文件权限与位置:
# 确保文件权限正确,Web服务可读取
sudo chmod 644 /var/www/html/sharing/apple-app-site-association
sudo chown www-data:www-data /var/www/html/sharing/apple-app-site-association
  • 验证JSON格式有效性:
# 用jq工具检查JSON格式,无报错则为有效
jq . /var/www/html/sharing/apple-app-site-association

若格式错误,根据提示修复后重新上传文件。

3. 验证结果

完成配置后,直接访问sharing.sample.app/apple-app-site-association确认能正常显示JSON内容,再通过AASA验证工具检测,确保所有错误项修复。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 16:15:32