If you are using NGINX’s main configuration file nginx.conf, without virtual hosts, then run the following command
$ sudo vi /etc/nginx/nginx.conf
If you have configured separate virtual hosts for your website (e.g www.example.com), such as /etc/nginx/sites-enabled/example.conf then open its configuration with the following command
$ sudo vi /etc/nginx/sites-enabled/example.conf
There are multiple ways to whitelist IP in NGINX. We will look at each of them. If you want to whitelist IP 126.96.36.199 for domain or your entire website, you can add the following lines in your configuration file.
The above lines will make NGINX deny all except IP 188.8.131.52. The first line allow 184.108.40.206 will allow access from that IP. deny all will block all other IPs.
Whitelist IP in NGINX for domain
Add the above lines in any of the http, server or location / blocks as shown below