網站首頁 編程語言 正文
Nginx不僅僅只是一款反向代理和負載均衡服務器,它還能提供很多強大的功能,例如:限流、緩存、黑白名單和灰度發布等等,我們先來了解一下nginx如何封禁ip和允許內網ip訪問。
一、語法
Nginx的ngx_http_access_module 模塊可以封配置內的ip或者ip段
deny IP; deny subnet; allow IP; allow subnet; # block all ips deny all; # allow all ips allow all;
二、封禁ip
假定nginx的目錄在/usr/local/nginx/
首先要建一個封ip的配置文件blockips.conf,然后在文件中輸入要封的ip?
deny 192.168.4.3;? deny 31.42.145.0/24;? deny 51.12.35.0/24;
然后保存此文件
并且打開nginx.conf文件,在http配置節內添加下面一行配置:
http { # 其他配置 include blockips.conf; }
測試現在的nginx配置文件是否是合法
/usr/local/nginx/sbin/nginx -t
如果配置沒有問題,就會輸出
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok?
configuration file /usr/local/nginx/conf/nginx.conf test is successful
如果配置有問題就需要檢查下哪兒有語法問題
如果沒有問題,需要執行下面命令,讓nginx重新載入配置文件?
/usr/local/nginx/sbin/nginx -s reload
三、僅內網IP訪問
配置如下
下面配置中禁止了192.168.1.1,允許其他內網網段,然后deny all禁止其他所有ip。
location / { # block one workstation deny 192.168.1.1; # allow anyone in 192.168.1.0/24 allow 192.168.1.0/24; # drop rest of the world deny all; }
原文鏈接:https://blog.csdn.net/weixin_41635750/article/details/123537951
相關推薦
- 2022-03-31 Python基礎中的列表你了解嗎_python
- 2023-03-22 Nginx轉發丟失cookie表現形式及解決方案_nginx
- 2022-12-06 Android?SwipeRefreshLayout超詳細講解_Android
- 2022-09-25 git問題:“ unable to auto-detect email address”或 “***
- 2023-07-22 macos設置環境變量path詳解
- 2022-04-26 python?moviepy?的用法入門篇_python
- 2023-04-08 c#?線程定時器?System.Threading.Timer的使用_C#教程
- 2022-09-07 GoLang使goroutine停止的五種方法實例_Golang
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支