구글에서 'Nginx IP 차단'이라고 검색하니 크롬 플로그인으로 설치 해놓았던 ChatGPT 플러그인이 답변을 해준다. 그런데 답변이 휼륭해서 너무 놀랍다. 구글링의 아성을 흔들 수 있다는 말이 실감된다.
참고 : [ChatGPT 활용법]
ChatGPT
To block IP addresses in Nginx, you can use the deny directive in the configuration file.
Here's an example of how to block a specific IP address:
location / {
deny 192.168.1.1;
allow all;
}
You can also block a range of IP addresses using a CIDR block:
location / {
deny 192.168.1.0/24;
allow all;
}
The deny directive should be placed inside the location block, and the allow directive should be used to specify which IP addresses should be allowed to access the site. In the example above, all IP addresses except for 192.168.1.1 and the range 192.168.1.0/24 will be allowed to access the site.
You can also use the allow directive to specify a list of allowed IP addresses, and use the deny directive to specify a list of denied IP addresses. For example:
location / {
allow 192.168.1.1;
allow 192.168.1.2;
deny all;
}
In this case, only the IP addresses 192.168.1.1 and 192.168.1.2 will be allowed to access the site, and all other IP addresses will be denied access.
Note that the allow and deny directives are evaluated in the order in which they appear in the configuration file. Therefore, it is important to place the deny directive after the allow directive, as shown in the examples above.
It is also possible to block IP addresses using the if directive and the $remote_addr variable. For example:
location / {
if ($remote_addr = 192.168.1.1) {
return 403;
}
}
This will return a 403 Forbidden error to the client if the client's IP address is 192.168.1.1.
I hope this helps! Let me know if you have any other questions.