相关文章:

高可用服务设计之二:Rate limiting 限流与降级

nginx限制请求之一:(ngx_http_limit_conn_module)模块

nginx限制请求之二:(ngx_http_limit_req_module)模块

nginx限制请求之三:Nginx+Lua+Redis 对请求进行限制

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

一个不错的nginx中针对目录进行IP限制 ,这里我以phpmyadmin目录只能让内网IP访问,而外网不能访问的配置方法,有需要的同学可参考。

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 针对内网ip用户开放、外网ip用户关闭(在前面的配置中,location ~ ^/目录/使用正则, 优先级高于location /的配置,所以nginx无法对首页进行解析)

我们也可以这样配置

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;
}

限制指定的连接只允许 某个指定的IP 能行访问

最新文章

  1. 用大白话聊聊JavaSE -- 自定义注解入门
  2. MYSQL低权限读文件
  3. FreeMarker模板语法
  4. All thanks
  5. 暴力枚举 UVA 725 Division
  6. TFS服务器(微软源代码管理服务器)上彻底删除项目
  7. HTTP层 —— Session
  8. 我的第一个Struts程序
  9. 多线程(NSThread、NSOperation、GCD)编程浅谈
  10. Ajax概述及浅谈其与服务器的交互过程
  11. json数据的获取(网络摘抄)
  12. windows上运行npm Error: ENOENT, stat 'C:\Users\
  13. 深入研究React setState的工作机制
  14. java 数组的冒泡排序
  15. ROS(indigo)一个简单灵活和可扩展的2D多机器人仿真器stdr_simulator
  16. ansible 模块
  17. Azkaban学习之路 (三)Azkaban的使用
  18. java ReentrantLock
  19. PL\SQL 随学笔记
  20. GZipStream 压缩与解压数据

热门文章

  1. Redis--初入
  2. myeclipes快捷键
  3. 我也说说Emacs吧(4) - 光标的移动
  4. 基于Ubuntu16.04的GeForce GTX 1080驱动安装,遇到的问题及对应的解决方法
  5. visual studio 一些小技巧 整理
  6. laravel 修改重置密码模板
  7. CentOS跨网段访问
  8. 新手向——关于Python3.5在Windows 10 系统下发布模块的终极讲解
  9. 微信小程序异常解析
  10. BZOJ2152 聪聪可可 【点分治】