Nginx禁止IP加端口访问
使用iptables
限制对应端口,再利用Nginx将80端口转发到对应端口
CentOS7默认的防火墙是 firewalle
,先看看服务器中有没有安装 iptables
[root@VM-0-3-centos ~]# service iptables status
Redirecting to /bin/systemctl status iptables.service
Unit iptables.service could not be found.
安装 iptables
?
1 |
yum install -y iptables |
关闭自带的防火墙 firewalld
?
1
2
3
4 |
# 停止firewalld服务
systemctl stop firewalld
# 禁用firewalld服务
systemctl mask firewalld |
服务命令
?
1
2
3
4
5
6
7
8 |
# 启动iptables
systemctl start iptables.service
# 停止iptables
systemctl stop iptables.service
# 重启iptables
systemctl restart iptables.service |
禁止外部访问8080
端口
?
1 |
iptables -I INPUT -p tcp --dport 8080 -j DROP |
允许本机访问8080
端口
?
1 |
iptables -I INPUT -s 127.0.0.1 -p tcp --dport 8080 -j ACCEPT |
放行80
端口
?
1
2 |
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT |
到此,就可以使用域名直接访问8080
端口了,并且IP + 端口
的方式,也已经无法访问
iptables
常用命令
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 |
# 查看iptables现有规则
iptables -L -n
# 允许所有访问
iptables -P INPUT ACCEPT
# 清空所有默认规则
iptables -F
# 清空所有自定义规则
iptables -X
# 所有计数器归0
iptables -Z
# 允许来自于lo接口的数据包(本地访问)
iptables -A INPUT -i lo -j ACCEPT
# 开放22端口
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# 开放21端口(FTP)
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
# 开放80端口(HTTP)
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
# 开放443端口(HTTPS)
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# 允许ping
iptables -A INPUT -p icmp --icmp- type 8 -j ACCEPT
# 允许接受本机请求之后的返回数据 RELATED,是为FTP设置的
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# 其他入站一律丢弃
iptables -P INPUT DROP
# 所有出站一律绿灯
iptables -P OUTPUT ACCEPT
# 所有转发一律丢弃
iptables -P FORWARD DROP |
到此这篇关于Nginx禁止ip加端口访问的文章就介绍到这了,更多相关Nginx禁止ip端口访问内容请搜索快网idc以前的文章或继续浏览下面的相关文章希望大家以后多多支持快网idc!
原文链接:https://www.cnblogs.com/zilongmao/archive/2022/02/11/15883833.html
相关文章
猜你喜欢
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
- 64M VPS建站:能否支持高流量网站运行? 2025-06-10
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-29 41
-
2025-05-29 93
-
2025-05-25 68
-
2025-05-25 40
-
2025-05-29 28
热门评论