nginx禁止限制某個IP位址或網段訪問伺服器

2022-05-20 16:56:27 字數 796 閱讀 5246

nginx配置訪問ip需要修改nginx.conf檔案,只需要在server中新增allow跟deny的ip即可,如下:

upstream novel 

server

error_page

500502

503504 /50x.html;

location = /50x.html

}ps: 上面的配置中allow必須在deny的前面配置,不然allow不生效。

下面是具體的配置

nginx中允許或者拒絕某個ip訪問是這麼寫的:

allow 192.168.0.1

;deny

192.168.0.2;

如果你需要對整個ip段設定不允許訪問,可以這麼寫:

deny 123.0.0.0/8;    //

封 123.0.0.1~123.255.255.254 這個段的ip

deny 123.1.0.0/16; //

封 123.1.0.1~123.1.255.254 這個段的ip

deny 123.1.1.0/24; //

封 123.1.1.1~123.1.1.254 這個段的ip

deny all;

//封所有ip

ps: allow跟deny配置相同,如果需要開放某個ip段,只需要把上面的deny改成allow

然後把需要配置的ip單獨寫在這個檔案上面,最後在nginx中引用這個檔案即可,如下:

server

nginx禁止某個IP訪問

有ip刷 想封掉這個ip,不讓他開啟 查資料,網上很多人說 etc hosts.deny 可以實現。其實是不行的。又不想用 iptable,感覺太麻煩。直接查 nginx阻止ip訪問的辦法。首先建立下面的配置檔案放在 nginx 的 conf目錄下面,命名為blocksip.conf deny 4....

nginx 禁止某個IP訪問

首先建立下面的配置檔案放在nginx的conf目錄下面,命名為blocksip.conf deny 95.105.25.181 儲存一下。在nginx的配置檔案nginx.conf中加入 include blocksip.conf 重啟一下nginx的服務 usr local nginx sbin ...

nginx 禁止某個IP訪問

首先建立下面的配置檔案放在nginx的conf目錄下面,命名為blocksip.conf deny 95.105.25.181 儲存一下。在nginx的配置檔案nginx.conf中加入 include blocksip.conf 重啟一下nginx的服務 usr local nginx sbin ...