[英]How to set content / mime type of apple-app-site-association as application/json
[英]How to set correct content-type for apple-app-site-association file on Nginx/Rails
为了为 iOS 应用程序设置通用链接,我创建了一个 apple-app-site-association 文件,并将它放在我的 Rails 应用程序的 /public 目录中。
我可以将它卷曲到正确的地址,但它返回了错误的内容类型。 它返回application/octet-stream
,而不是application/json
或application/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 以提供具有正确内容类型的文件的正确方法是什么?
在 Nginx 中添加:
location ~ /.well-known/apple-app-site-association {
default_type application/pkcs7-mime;
}
以上对我不起作用,但我想我会在这里发布以防它对其他人有帮助。 我需要 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]
这在 .htaccess 中对我有用:
<FilesMatch "apple-app-site-association">
ForceType application/json
</FilesMatch>
原来 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*"
]
}
]
}
就我而言,我会为“apple-app-site-association”创建一个单独的 nginx
将此文件定位到 /usr/share/nginx/html/apple-app-site-association 和 /usr/share/nginx/html/.well-known/apple-app-site-association
编辑 /etc/nginx/nginx.conf 并设置 default_type application/json;
就是这样。
测试它,
curl -i localhost/apple-app-site-association
HTTP/1.1 200 OK 服务器:nginx/1.19.3 日期:2020 年 10 月 29 日星期四 13:34:00 GMT 内容类型:application/json 内容长度:198 最后修改时间:2020 年 10 月 23 日星期五 13:54: 03 GMT 连接:保持活动 ETag:“5f92e07b-c6”接受范围:字节
{ "applinks": { "apps": [], "details": [ { "appID": "APPPREFIX.com.mycompany.app", "paths": [ "*" ] } ] } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.