Nostr NIP-05 specification makes it a bit harder to serve identifiers from a simple webserver without CGI to run an external program handling the name
URL query parameter. I really didn't want to do all that, so instead I focused on how to handle everything just in Nginx itself.
- A server with Nginx responding to basic requests. (minimal configuration should be enough)
Inside the http
block insert map
and map_hash_bucket_size
directives:
map_hash_bucket_size 256;
map $arg_name $nostr_key {
default 'error - handle not found';
'handle1' 'handle1's nostr pub key in HEX';
'handle2' 'handle2's nostr pub key in HEX';
}
Notice that the map_hash_bucket_size
is set to 256. It is my guesstimation of what should be enough for holding identities for you, your family, and friends. Consult Nginx documentation for more details.
Then add the following Location
directive to the server
block:
location /.well-known/nostr.json {
add_header Access-Control-Allow-Origin *;
if ($arg_name) {
return 200 "{\"names\":{\"$arg_name\":\"$nostr_key\"}}";
}
}
Again notice the addition of header allowing cross-domain requests.
If you want to, NIP-05 offers the optional relays
attribute. To return it as well we will need another map
module:
map $arg_name $nostr_relays {
default '"error - handle not found"';
'handle1' '["wss://example.test"]';
'handle2' '["wss://example.test", "wss://example2.test"]';
}
The Location
then needs to be adjusted to look like to this:
location /.well-known/nostr.json {
add_header Access-Control-Allow-Origin *;
if ($arg_name) {
return 200 "{\"names\":{\"$arg_name\":\"$nostr_key\"}, \"relays\": {\"$nostr_key\": $nostr_relays} }";
}
}
The above text and configuration snippets are released as Public Domain.
If you like it feel free to zap away at npub1ajdaw3j4g6aqv86alhn3df8jpulj0mxz3jjgwpm4uh598hc348gqthdt20