'How to do reverse DNS lookup in Nginx

I have Nginx configuration where I want to allow a DNS name as I cant be certain on IP address.

{
 satisfy any;
 allow www.domain.com; // want to achieve this
}

With Nginx we cant achieve this.

  • Looked at this https://github.com/flant/nginx-http-rdns as a solution. This module says it does reverse lookup but it didnt work and repo is very old and well maintained.

  • Another alternative is to use a shell script and do a dig or host on IP address but we dont want to use shell script with Nginx.

  • Alternate solution is to use a side car to do the DNS resolution and to add allow/deny rules.



Solution 1:[1]

If this still works you'll need to compile it for the same version of nginx that is installed. If you're using nginx from a repo then dynamically compile it and see if the following helps:

Download nginx src matching installed version and extract it.

$ cd nginx-1.x.x
$ ./configure --with-compat --add-dynamic-module=/path/to/nginx_module
$ make modules

make modules should result in a nginx module that you need to copy to /usr/lib/nginx/modules/ and load it with load_module modules/modulename.so in your nginx.conf.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1