Nginx权限控制access_module配置
2018-03-30 本文已影响239人
洋葱cy
Nginx下可以使用access_modue模块进行对ip的访问限制
语法 | 含义 | 实例 |
---|---|---|
allow | 允许的访问IP | allow all; allow x.x.x.x; allow x.x.x.x/x; |
deny | 不允许的IP | deny all; dengy x.x.x.x; deny x.x.x.x/x; |
修改以下文件,对本机ip加入限制
/etc/nginx/conf.d/default.conf
server {
listen 8089;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location /mystatus {
stub_status;
}
location / {
root /zhang/nginx/app/code;
#index index.html index.htm;
random_index on;
}
#对1.html进行本机的IP访问限制
location ~ ^/1.html {
deny 180.169.146.185;
allow all;
}
}
验证nginx.conf的合法性,重新加载配置文件
nginx -tc /etc/nginx/nginx.conf
nginx -s reload -c /etc/nginx/nginx.conf
访问nginx 8089 1.html,显示被拒绝

访问nginx 8089 2.html 访问成功
