nginx中针对目录进行IP限制
2015-10-28 23:52
591 查看
一个不错的nginx中针对目录进行IP限制 ,这里我以phpmyadmin目录只能让内网IP访问,而外网不能访问的配置方法,有需要的同学可参考。
nginx phpmyadmin 针对内网ip用户开放、外网ip用户关闭(在前面的配置中,location ~ ^/目录/使用正则, 优先级高于location /的配置,所以nginx无法对首页进行解析)
我们也可以这样配置
限制指定的连接只允许 某个指定的IP 能行访问
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 ~ ^/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; } } |
代码如下 | 复制代码 |
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; } |
相关文章推荐
- nginx上传目录配置,禁止执行权限
- CTO之nginx在ubuntu下删除记录
- nginx 负载均衡
- nginx中配置跨域支持功能
- CentOS 6.5 + Nginx 1.8.0 + PHP 5.6(with PHP-FPM) 负载均衡源码安装 之 (一)Nginx安装篇
- 最完美ThinkPHP nginx 配置文件
- centos6.7系统rpm安装Nginx+PHP+MYSQL
- nginx+php(php-fpm)安装配置
- Nginx基础入门之nginx部署安装
- 解剖Nginx·自动脚本篇
- nginx知识点总结
- Nginx 和 PHP 的两种部署方式比较
- Ubuntu Wiki指导安装Nginx +mysql+php
- Nginx 内存池(pool)分析
- 修复Nginx报错:upstream sent too big header while reading response header from upstream
- Nginx作为gitweb服务器
- nginx本身不能提高性能
- Nginx中502和504错误详解
- 最全面 Nginx 入门教程 + 常用配置解析
- nginx与HA