【问题标题】:How to set correct content-type for apple-app-site-association file on Nginx/Rails如何在 Nginx/Rails 上为 apple-app-site-association 文件设置正确的内容类型
【发布时间】:2016-11-21 16:43:13
【问题描述】:

为了为 iOS 应用程序设置通用链接,我创建了一个 apple-app-site-association 文件,并将它放在我的 Rails 应用程序的 /public 目录中。

我可以在正确的地址卷曲它,但它返回错误的内容类型。它返回application/octet-stream,而不是application/jsonapplication/pkcs7-mime,正如您在此处的响应中看到的那样:

curl -i https://example.com/apple-app-site-association

HTTP/1.1 200 OK
Server: nginx/1.10.1
Content-Type: application/octet-stream
Content-Length: 245
Last-Modified: Mon, 21 Nov 2016 12:45:00 GMT
Strict-Transport-Security: max-age=31536000

{
  "applinks": {
    "apps": [],
    "details": [
      {
        "appID": "APPPREFIX.com.mycompany.app",
        "paths": [
          "/home*"
        ]
      }
    ]
  }

我正在尝试在 nginx 配置中指定 Content-Type:

/etc/nginx/sites/sites-available/sitename: 

server {
   ...
   location /apple-app-site-association {
      default_type application/pkcs7-mime;
   }
}

我已保存此更改并重新启动 nginx。这对 curl 的响应没有任何影响。我还尝试了location /public/apple-app-site-association {} 和其他一些变体,但没有效果。

设置 nginx 以提供具有正确内容类型的文件的正确方法是什么?

【问题讨论】:

    标签: ios nginx ios-universal-links


    【解决方案1】:

    这在 .htaccess 中对我有用:

    <FilesMatch "apple-app-site-association">
        ForceType application/json
    </FilesMatch>
    

    【讨论】:

      【解决方案2】:

      在 nginx 中添加:

      location ~ /.well-known/apple-app-site-association {
               default_type application/pkcs7-mime;
       }
      

      【讨论】:

        【解决方案3】:

        以上内容对我不起作用,但我想我会在这里发布以防万一它帮助其他人。我需要将 apple-app-site-association 设为 application/json,因此将文件名更改为 apple-app-site-association.json,然后将其添加到 /.well-known 中的 .htaccess

        RewriteEngine On
        RewriteBase /.well-known/
        
        # iOS
        RewriteRule ^apple-app-site-association$ apple-app-site-association.json [NC,L] 
        

        【讨论】:

          【解决方案4】:

          原来 nginx 配置文件描述了两台服务器,而我将位置 sn-p 添加到错误的一台。

          当我将其添加到正确的文件并重新加载 nginx 时,返回的文件具有预期的内容类型:

          HTTP/1.1 200 OK
          Server: nginx/1.10.1
          Content-Type: application/pkcs7-mime
          Content-Length: 245
          
          {
          "applinks": {
          "apps": [],
          "details": [
            {
              "appID": "APPPREFIX.com.mycompany.app",
              "paths": [
                "/home*"
              ]
            }
          ]
          

          }

          【讨论】:

            【解决方案5】:

            就我而言,我会为“apple-app-site-association”创建一个单独的 nginx

            1. 将此文件定位到 /usr/share/nginx/html/apple-app-site-association 并在 /usr/share/nginx/html/.well-known/apple-app-site-association

            2. 编辑,/etc/nginx/nginx.conf 并设置 default_type application/json;

            3. 就是这样。

            测试一下,

            1. curl -i localhost/apple-app-site-association

              HTTP/1.1 200 正常 服务器:nginx/1.19.3 日期:格林威治标准时间 2020 年 10 月 29 日星期四 13:34:00 内容类型:应用程序/json 内容长度:198 最后修改时间:格林威治标准时间 2020 年 10 月 23 日星期五 13:54:03 连接:保持活动 ETag:“5f92e07b-c6” 接受范围:字节

              { “应用链接”:{ “应用”: [], “细节”: [ { "appID": "APPPREFIX.com.mycompany.app", “路径”:[“*”] } ] } }

            【讨论】:

              猜你喜欢
              • 2017-05-06
              • 2020-08-28
              • 2018-01-05
              • 1970-01-01
              • 2021-06-02
              • 2022-01-09
              • 1970-01-01
              • 2014-10-06
              • 2016-01-06
              相关资源
              最近更新 更多