http_access_module
location / { deny 192.168.1.1; # 拒绝访问 allow 192.168.1.0/24; # 允许访问 allow 10.1.1.0/16; allow 2001:0db8::/32; # IPV6 deny all; }基于的是客户端的IP,如果有代理则无法识别。 解决:http_x_forwarded_for http_x_forwarded_for = 客户端ip,第一台代理ip,第二台代理ip,第N台代理ip…,所以http_x_forwarded_for是由一连串以逗号分隔的ip组成的。
但是http_x_forwarded_for进行访问控制会存在问题,因为是一个协议要求的,并不是所有的cdn和代理厂商它会按照要求来做,甚至x_forwarded_for存在被修改的可能,因为只是一个头信息,所以最终还是不真实。
http_auth_basic_module
yum install httpd-tools -y htpasswd -c ./user_passwd admin location / { auth_basic "输入密码"; auth_basic_user_file user_passwd; }用户信息依赖文件方式,管理操作机械,效率不高。 解决:nginx_auth_ldap 安装参考
http { ldap_server openldap { url ldap://192.168.192.20:389/dc=example,dc=com?uid?sub?(&(objectClass=account)); binddn "cn=Manager,dc=example,dc=com"; binddn_passwd "secret"; group_attribute memberuid; group_attribute_is_dn on; require valid_user; } } server { location /status { stub_status on; access_log off; auth_ldap "Restricted Space"; auth_ldap_servers openldap; } }