Skip to content

Instantly share code, notes, and snippets.

@agrueneberg
Last active April 30, 2023 22:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save agrueneberg/5693181 to your computer and use it in GitHub Desktop.
Save agrueneberg/5693181 to your computer and use it in GitHub Desktop.
A simple WebFinger resource for nginx (compatible with draft-ietf-appsawg-webfinger-14.txt).
location ~ /.well-known/webfinger {
add_header 'Access-Control-Allow-Origin' '*';
if ($arg_resource = "") {
return 400;
}
try_files /profiles/$arg_resource.json =404;
}
@agrueneberg
Copy link
Author

Add application/json json; to /etc/nginx/mime.types to serve the files with the right Content-Type. Optionally, add application/json to charset_types if you want to specify the charset in the Content-Type.

@agrueneberg
Copy link
Author

Note that nginx doesn't decode URL parameters, so the file names have to be URL encoded as well: ?resource=acct%3Abob%40example.com will look for a file called /profiles/acct%3Abob%40example.com.json. I suggest symlinks as a workaround to accept unencoded resource parameters.

@agrueneberg
Copy link
Author

There is now a dedicated repository for this: https://github.com/agrueneberg/nginx-webfinger Please report issues there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment