如何在 Nginx/Rails 上为 apple-app-site-association 文件设置正确的内容类型
How to set correct content-type for apple-app-site-association file on Nginx/Rails
为了为 iOS 应用程序设置通用链接,我创建了一个 apple-app-site-association 文件,并将其放在我的 [=] 的 /public 目录中29=] 应用程序。
我可以将其卷曲到正确的地址,但 returns 内容类型错误。而不是 application/json
或 application/pkcs7-mime
它 returns 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*"
]
}
]
}
我试图在 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 配置文件描述了两台服务器,而我将位置片段添加到错误的服务器。
当我将它添加到正确的文件并重新加载 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*"
]
}
]
}
以上内容对我不起作用,但我想我会 post 在这里,以防它对其他人有帮助。我需要 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]
在nginx中添加:
location ~ /.well-known/apple-app-site-association {
default_type application/pkcs7-mime;
}
这在 .htaccess 中对我有用:
<FilesMatch "apple-app-site-association">
ForceType application/json
</FilesMatch>
在我的例子中,我会为“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 行
服务器:nginx/1.19.3
日期:2020 年 10 月 29 日,星期四 13:34:00 GMT
Content-Type: application/json
Content-Length: 198
Last-Modified:2020 年 10 月 23 日,星期五 13:54:03 GMT
连接:keep-alive
ETag:“5f92e07b-c6”
Accept-Ranges:字节数
{
“应用程序链接”:{
“应用”: [],
“细节”: [
{
"appID": "APPPREFIX.com.mycompany.app",
“路径”:[“*”]
}
]
}
}
为了为 iOS 应用程序设置通用链接,我创建了一个 apple-app-site-association 文件,并将其放在我的 [=] 的 /public 目录中29=] 应用程序。
我可以将其卷曲到正确的地址,但 returns 内容类型错误。而不是 application/json
或 application/pkcs7-mime
它 returns 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*"
]
}
]
}
我试图在 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 配置文件描述了两台服务器,而我将位置片段添加到错误的服务器。
当我将它添加到正确的文件并重新加载 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*"
]
}
]
}
以上内容对我不起作用,但我想我会 post 在这里,以防它对其他人有帮助。我需要 apple-app-site-association application/json 所以将文件名更改为 apple-app-site-association.json 然后将其添加到 /.well-known
中的 .htaccessRewriteEngine On
RewriteBase /.well-known/
# iOS
RewriteRule ^apple-app-site-association$ apple-app-site-association.json [NC,L]
在nginx中添加:
location ~ /.well-known/apple-app-site-association {
default_type application/pkcs7-mime;
}
这在 .htaccess 中对我有用:
<FilesMatch "apple-app-site-association">
ForceType application/json
</FilesMatch>
在我的例子中,我会为“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 行 服务器:nginx/1.19.3 日期:2020 年 10 月 29 日,星期四 13:34:00 GMT Content-Type: application/json Content-Length: 198 Last-Modified:2020 年 10 月 23 日,星期五 13:54:03 GMT 连接:keep-alive ETag:“5f92e07b-c6” Accept-Ranges:字节数
{ “应用程序链接”:{ “应用”: [], “细节”: [ { "appID": "APPPREFIX.com.mycompany.app", “路径”:[“*”] } ] } }