Serving Apple App Site Association file using Nginx for React Apps
The AASA (short for apple-app-site-association) is a file that lives on your website and associates your website domain with your native app. In other words, it’s a safe way to prove domain ownership to iOS for deep linking.
There is no way to serve the apple-app-site-association from a react app. So we have to push the AASA file from the Nginx server.
Step 1 — Copy the AASA file to the server
Copy the AASA file apple-app-site-association.json
or apple-app-site-association.applescript
file to a particular location in the server.
I have uploaded the file in the following directory
/var/www/certificates/ios/
Step 2— Add a route to the Nginx config file
Go to the file where the Nginx config is written. Its usually in /etc/nginx/sites-enabled/default
. To open the file, try the following commands in terminal
cd /etc/nginx/sites-enabled/sudo vim default
Add the following config to the Nginx configuration file above the line where you find this location / {
location /apple-app-site-association {
alias /var/www/certificates/ios/;
index apple-app-site-association.json
autoindex on;
}
Step 3 — Check and Restart the Nginx server
To check if your Nginx configuration is correct, run the below command in a terminal
nginx -t
If you get the following output then you are good to go. Else, there is something wrong with your Nginx server configuration.
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Now, restart the Nginx server for the changes to take effect.
sudo service nginx restart
Step 4— Testing the output
Now when to try to visit the route /apple-app-site-association
you will be served the apple-app-site-association.json
file
https://example.com/apple-app-site-association
The complete default file is given below
Hooray!!, Now you can provide domain ownership for apple using the AASA file.
Say Hi, It’s free at @matheswaaran_S or https://matheswaaran.com