Linux_WEB访问控制示例(使用IPADDR类型)
前言:
WEB服务使用访问控制,可以控制IP、主机名、以及某个网段的IP去访问我们的WEB服务,从而加减少流量的访问
一、使用IP控制访问
1、在/var/www/html下创建一个可访问的测试页面
1 2 3 4 5 6 7 | [root@localhost ~] # cd /var/www/html/ [root@localhost html] # mkdir test [root@localhost html] # cd test/ [root@localhost test ] # ls [root@localhost test ] # vim index.html [root@localhost test ] # cat index.html Hello Word |
2、在浏览器访问测试是否可以访问
测试确实可以访问!!!
3、在/etc/httpd/conf/httpd.conf配置文件里面添加访问控制信息
1 2 3 4 5 6 7 8 9 | [root@localhost ~] # cd /etc/httpd/conf/ [root@localhost conf] # vim httpd.conf ............ <directory "/var/www/html/test" > <requireall> require not ip 192.168.121.1 // 这个地址并不是网卡的IP地址,应该是使用访问WEB服务的地址;一般是网卡的地址(也可以在 /etc/httpd/logs/access_log 访问日志文件里面查看访问地址) require all granted // 因为默认是拒绝的,必须添加允许所有主机访问 < /requireall > < /directory > |
4、重启服务
1 2 3 4 5 6 7 8 9 10 | // 检测语法是否有错 [root@localhost conf] # httpd -t Syntax OK [root@localhost conf] # systemctl restart httpd [root@localhost conf] # ss -antlp State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN0 128 0.0.0.0:22 0.0.0.0:* users :(( "sshd" ,pid=1020,fd=4)) LISTEN0 128 *:80 *:* users :(( "httpd" ,pid=15466,fd=4),( "httpd" ,pid=15465,fd=4),( "httpd" ,pid=15464,fd=4),( "httpd" ,pid=15462,fd=4)) LISTEN0 128 [::]:22 [::]:* users :(( "sshd" ,pid=1020,fd=6)) |
5、再次测试访问
已经限制访问!!!
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步