I’m trying to serve my AppLink for google association services. The following works:
location /.well-known/assetlinks.json {
root /var/www/static/google-association-service/;
types { } default_type "content-type: application/json";
}
Provided I have the correct file placed at
/var/www/static/google-association-service/.well-known/assetlinks.json
The URI is what it it is, Google gets to decide that, but I’d rather not have it resolve to a hidden file at the bottom of a directory where the next guy wonders why the directory is even there because he forgot to ls with a ‘-a’. Is there a way to make it so I can map this URI to something like:
/var/www/static/google-association-service/assetlinks.json
# omit the hidden sub directory
?
(I’ve tried understanding the difference between root and alias, but I’m not seeing how alias would help me here)
2
Answers
You can use
try_files
to find the specific file you want.For example:
Or:
The concatenation of the
root
value and thetry_files
parameter form the path to the file.alias
basically gives you the possibility to serve a file with another name (e.g. serve a file namedfoo.json
at location/.well-known/assetlinks.json
). Even if this is not required in your case I would favor this config, as it is easily understandable:Note that the
=
is required to not match locations like/.well-known/assetlinks.json1111
.