Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to not need a .dotted file path in nginx configuration

Tags:

nginx

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)

like image 772
Travis Griggs Avatar asked Sep 20 '25 21:09

Travis Griggs


2 Answers

alias basically gives you the possibility to serve a file with another name (e.g. serve a file named foo.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:

location = /.well-known/assetlinks.json {
    alias /var/www/static/google-association-service/assetlinks.json;
}

Note that the = is required to not match locations like /.well-known/assetlinks.json1111.

like image 194
slauth Avatar answered Sep 23 '25 13:09

slauth


You can use try_files to find the specific file you want.

For example:

location = /.well-known/assetlinks.json {
    root /var/www/static/google-association-service;
    try_files /assetlinks.json =404;
}

Or:

location = /.well-known/assetlinks.json {
    root /var/www/static;
    try_files /google-association-service/assetlinks.json =404;
}

The concatenation of the root value and the try_files parameter form the path to the file.

like image 28
Richard Smith Avatar answered Sep 23 '25 11:09

Richard Smith