手冊-Module ngx_stream_access_module
Module ngx_http_access_module
隨便寫一個 .conf結尾的配置文件蝙昙, 比如我們此處用 ip.conf文件
ip.conf 文件
# 屏蔽127.0.0.1
deny 127.0.0.1;
# 屏蔽所有ip
deny all;
# 允許127.0.0.1,192.168.1.1
allow 127.0.0.1;
allow 192.168.1.1;
# 允許所有ip進入
allow all;
#屏蔽整個段即從123.0.0.1到123.255.255.254訪問的命令
deny 123.0.0.0/8
#屏蔽IP段即從123.45.0.1到123.45.255.254訪問的命令
deny 123.45.6.0/24
然后進入配置文件的`http`模塊低葫,或者`server`文件,或者`server`里面的`localtion`匹配模塊都可以
但是我們大多的需求其實是在 server里面
ngx_http_access_module
模塊和ngx_stream_access_module
模塊實現(xiàn)屏蔽方式是一樣的惨恭,都是deny
和access
只是寫在server
配置里面的就是ngx_stream_access_module
模塊實現(xiàn)巧婶,location
是ngx_http_access_module
模塊實現(xiàn)
location / {
deny 192.168.1.1;
allow 192.168.1.0/24;
allow 10.1.1.0/16;
allow 2001:0db8::/32;
deny all;
}
server {
...
deny 192.168.1.1;
allow 192.168.1.0/24;
allow 10.1.1.0/16;
allow 2001:0db8::/32;
deny all;
}
或者把IP寫到一個文件里面 比如ip.conf
然后在站點配置里面的 server添加
server{
include /etc/nginx/ip.conf;
}