In order to set up universal links for an iOS app, I have created an apple-app-site-association file, and placed it in the /public directory of my Rails app.
I can curl it at the correct address, but it returns the wrong content type. Instead of application/json
or application/pkcs7-mime
it returns application/octet-stream
, as you can see in the response here:
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*"
]
}
]
}
I am attempting to specify a Content-Type in the nginx configuration:
/etc/nginx/sites/sites-available/sitename:
server {
...
location /apple-app-site-association {
default_type application/pkcs7-mime;
}
}
I have saved this change and restarted nginx. This doesn't make any difference to the response from curl. I've also tried location /public/apple-app-site-association {}
and a few other variations, to no effect.
What is the correct way to set up nginx to deliver this file with the correct content type?
Add in nginx:
location ~ /.well-known/apple-app-site-association {
default_type application/pkcs7-mime;
}
The above didn't work for me but thought I'd post here in case it helps anyone else. I needed apple-app-site-association to be application/json so changed the filename to apple-app-site-association.json then added this to .htaccess within /.well-known
RewriteEngine On
RewriteBase /.well-known/
# iOS
RewriteRule ^apple-app-site-association$ apple-app-site-association.json [NC,L]
This worked for me within .htaccess:
<FilesMatch "apple-app-site-association">
ForceType application/json
</FilesMatch>
It turns out the nginx configuration file described two servers, and I was adding the location snippet to the wrong one.
When I added it to the correct one and reloaded nginx, the file was returned with the expected content-type:
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*"
]
}
]
}
In my case, I'd create a separate nginx for "apple-app-site-association"
locate this file to /usr/share/nginx/html/apple-app-site-association and in /usr/share/nginx/html/.well-known/apple-app-site-association
edit, /etc/nginx/nginx.conf and set default_type application/json;
that is it.
to test it,
curl -i localhost/apple-app-site-association
HTTP/1.1 200 OK Server: nginx/1.19.3 Date: Thu, 29 Oct 2020 13:34:00 GMT Content-Type: application/json Content-Length: 198 Last-Modified: Fri, 23 Oct 2020 13:54:03 GMT Connection: keep-alive ETag: "5f92e07b-c6" Accept-Ranges: bytes
{ "applinks": { "apps": [], "details": [ { "appID": "APPPREFIX.com.mycompany.app", "paths": [ "*" ] } ] } }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.