nginx设置ip黑名单

发布时间:2021-11-01 14:15:06

1、在配置文件目录下如:/usr/local/nginx/conf/vhosts/下创建黑名单文件ip.black(叫啥都行)
      在文件内容写上列入黑名单的IP,格式为deny IP;

#拒绝访问IP

deny 85.209.43.252;

2、在nginx.conf进行配置

http {

    include     vhosts/ip.black;

    include       mime.types;

    default_type  application/octet-stream;

3、日志效果

2021/11/01 14:09:22 [error] 6679#0: *5790682 access forbidden by rule, client: 85.209.43.252, server: localhost, request: "GET / HTTP/1.1",