skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search