日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

nginx限制请求之四:目录进行IP限制

發(fā)布時(shí)間:2025/7/14 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nginx限制请求之四:目录进行IP限制 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

相關(guān)文章:

《高可用服務(wù)設(shè)計(jì)之二:Rate limiting 限流與降級(jí)》

《nginx限制請(qǐng)求之一:(ngx_http_limit_conn_module)模塊》

《nginx限制請(qǐng)求之二:(ngx_http_limit_req_module)模塊》

《nginx限制請(qǐng)求之三:Nginx+Lua+Redis 對(duì)請(qǐng)求進(jìn)行限制》

《nginx限制請(qǐng)求之四:目錄進(jìn)行IP限制》

?

一個(gè)不錯(cuò)的nginx中針對(duì)目錄進(jìn)行IP限制 ,這里我以phpmyadmin目錄只能讓內(nèi)網(wǎng)IP訪問,而外網(wǎng)不能訪問的配置方法,有需要的同學(xué)可參考。

server {listen 80;server_name example.com;access_log logs/access.log main;location / {root html;index index.php index.html index.htm;}location ~ ^/phpmyadmin/ {allow 192.168.1.0/24;deny all;location ~ .*.(php|php5)?$ {root /var/mailapp/nginx/html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;include fastcgi_params;}}location ~ .*.(php|php5)?$ {root /opt/nginx/html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;include fastcgi_params;}}

nginx?phpmyadmin?針對(duì)內(nèi)網(wǎng)ip用戶開放、外網(wǎng)ip用戶關(guān)閉(在前面的配置中,location ~ ^/目錄/使用正則, 優(yōu)先級(jí)高于location /的配置,所以nginx無法對(duì)首頁進(jìn)行解析)

我們也可以這樣配置

?

server {listen 80;server_name example.com;access_log logs/access.log main;location / {root html;index index.php index.html index.htm;}location ~ ^/download/ {allow 192.168.1.0/24;deny all;index index.php index.do index.html index.htm;location ~ .*.(php|php5)?$ {root /var/mailapp/nginx/html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;include fastcgi_params;}}location ~ .*.(php|php5)?$ {root /opt/nginx/html;astcgi_pass 127.0.0.1:9000;fastcgi_index index.php;include fastcgi_params;}

限制指定的連接只允許 某個(gè)指定的IP 能行訪問

總結(jié)

以上是生活随笔為你收集整理的nginx限制请求之四:目录进行IP限制的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。