如何在Nginx / Rails上为apple-app-site-association文件设置正确的内容类型

Ali*_*i H 5 nginx ios ios-universal-links

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

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

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*"
        ]
      }
    ]
  }
Run Code Online (Sandbox Code Playgroud)

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

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

server {
   ...
   location /apple-app-site-association {
      default_type application/pkcs7-mime;
   }
}
Run Code Online (Sandbox Code Playgroud)

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

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

Yar*_*ron 18

这在 .htaccess 中对我有用:

<FilesMatch "apple-app-site-association">
    ForceType application/json
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)


Pau*_*ips 7

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

RewriteEngine On
RewriteBase /.well-known/

# iOS
RewriteRule ^apple-app-site-association$ apple-app-site-association.json [NC,L] 
Run Code Online (Sandbox Code Playgroud)


Pab*_*rra 6

在 Nginx 中添加:

location ~ /.well-known/apple-app-site-association {
         default_type application/pkcs7-mime;
 }
Run Code Online (Sandbox Code Playgroud)


Ali*_*i H 3

事实证明,nginx 配置文件描述了两台服务器,而我将位置片段添加到了错误的服务器中。

当我将其添加到正确的文件并重新加载 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*"
    ]
  }
]
Run Code Online (Sandbox Code Playgroud)

}