date: 2019-07-04  14:35:56

author: headsen chen

notice: 个人原创

1,在分域名下面设置:

[root@pro-nginx:/usr/local/openresty/nginx/conf/sites]$cat www.ceshi.com.conf
geo $remote_addr $black {
121.35.3.0/24 1;
121.35.2.0/24 1;
121.35.1.0/24 1;
121.35.0.0/24 1;
112.97.63.0/24 1;
112.97.50.0/24 1;
211.101.18.214 1;
124.232.148.90 1;
118.193.154.149 1;
140.240.23.99 1;
}
server {
listen 80;
listen 443 ssl;
include ceshi-ssl-ev.conf;
server_name www.ceshi.com;

2,在分域名下面设置(设置在匹配项下面的):

location / {
  deny 192.168.1.1;
  allow 192.168.1.0/24;
  allow 10.1.1.0/16;
  allow 2001:0db8::/32;
  deny all;
  proxy_pass http://10.1.1.1:2000;
}

3,在Nginx的总入口上配置访问ip限制,只有在白名单里面的才可以访问。

[root@beta-usrv01:/usr/local/openresty/nginx/conf]$cat nginx.conf
user fmservice;
worker_processes auto;
events {
worker_connections 102400;
} http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server_names_hash_bucket_size 128;
log_format main '$remote_addr [$time_local] "$host" "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'"$request_time:$upstream_response_time" $upstream_addr "$upstream_status" "$upstream_cache_status"';
client_max_body_size 50m;
gzip on;
gzip_types text/plain application/javascript application/x-javascript text/xml text/css image/png image/jpg image/gif image/jpeg;
gzip_vary off;
geo $remote_addr $whitelist {
default 0;
127.0.0.1 1;
172.0.0.0/8 1;
10.0.0.0/8 1;
119.189.0.0/16 1;
113.169.0.0/16 1;
139.108.102.77 1;
112.174.61.155 1;
120.178.139.70 1
;
......
} map $http_x_app_info $appheader {
default "";
}
} 也可以分开写:
[root@metabase:/usr/local/openresty/nginx/conf]$cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
} http {
include mime.types;
default_type application/octet-stream; log_format main '$remote_addr [$time_local] "$host" "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'"$request_time:$upstream_response_time" $upstream_addr "$upstream_status" "$upstream_cache_status"'; access_log logs/access.log main;
error_log logs/error.log;
sendfile on;
keepalive_timeout 65;
include whiteiplist.conf;
server {
listen 80;
server_name aaaa.bbbbbbl.com default;
access_log /var/log/nginx/aaaaa.bbbbbbl.com.log main; if ( $whitelist != 1 ) {
return 403;
#set $fasdbfad 1;
}
[root@metabase:/usr/local/openresty/nginx/conf]$cat whiteiplist.conf 
geo $remote_addr $whitelist {
default 0;
101.232.131.102 1;
124.42.150.166 1;
117.136.40.216 1;
}

Nginx设置黑名单的更多相关文章

  1. Nginx设置线程数为整机内核数的俩倍!

    Nginx设置线程数为整机内核数的俩倍!

  2. nginx设置不使用缓存 add_header Cache-Control no-cache

    nginx设置不使用缓存 server { listen 443; #域名 server_name www.dev.163.com; #字符集 charset utf-8; ssl on; ssl_c ...

  3. nginx设置SSL反向代理

    Nginx的反向代理通常用来映射内网中提供的Apache.IIS.Lighttpd服务,以实现负载均衡:同时,由于动态服务程序运行在内网,服务器的整体安全性也有所提高,那么怎样用nginx设置SSL的 ...

  4. 给postfix设置黑名单

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  5. nginx 设置进程title

    刚好看到nginx设置进程title的源码,因此做一些总结. linux进程实际是以argv[0]处的值来作为进程的title的,因此若需要修改进程的title只需要修改argv[0]处的值即可. 简 ...

  6. Nginx设置Https反向代理,指向Docker Gitlab11.3.9 Https服务

    目录 目录 1.GitLab11.3.9的安装 2.域名在阿里云托管,申请免费的1年证书 3.Gitlab 的 https 配置 4.Nginx 配置 https,反向代理指向 Gitlab 配置 目 ...

  7. Nginx设置网站维护页面

    网站升级需要停服,可以在Nginx设置静态页面设置强制跳转 修改nginx配置文件nginx.conf http { sendfile on; keepalive_timeout 65; server ...

  8. Nginx 设置临时维护页面

    Nginx 设置临时维护页面 http://www.myexception.cn/open-source/1753957.html http://blog.justwd.net/snippets/ng ...

  9. nginx 设置默认虚拟 host

    nginx 设置默认虚拟 host listren 80 default_server

随机推荐

  1. uboot中setenv和saveenv分析

    转:https://blog.csdn.net/weixin_34355715/article/details/85751477 Env在u-boot中通常有两种存在方式,在永久性存储介质中(flas ...

  2. PYTHON 爬虫 baidu美女图片

    from urllib import requestimport re import osdef main(): #page=request.urlopen("http://image.ba ...

  3. numpy模块的基本使用

    numpy(Numerical Python)提供了python对多维数组对象的支持:ndarray,具有矢量运算能力,快速.节省空间.numpy支持高级大量的维度数组与矩阵运算,此外也针对数组运算提 ...

  4. 关于前端 jQuery 面试的知识点

    参考一个博主整理的一些前端 jQuery 的一些面试题 参考博客:https://www.cnblogs.com/dashucoding/p/11140325.html 参考博客:https://ww ...

  5. Hadoop集群分布搭建

    一.准备工作 1.最少三台虚拟机或者实体机(官网上是默认是3台),我这边是3台 s1: 10.211.55.18 s2: 10.211.55.19 s3: 10.211.55.20 2.安装JDK 3 ...

  6. JavaSctipt 常用字符串 方法及使用方式

    1. charAt(x) charAt(x)返回字符串中x位置的字符,下标从 0 开始. //charAt(x) var myString = 'jQuery FTW!!!'; console.log ...

  7. Ftp客户端需要TSL功能的文件上传

    Ftp客户端需要TSL功能 1.由于最近做了一个项目,需要把打包的文件传输到对方的FTP服务器上,但是用普通的java连接ftp客户端总是连接不上去,对方却说ftp客户端需要开通TSL功能. 直接上代 ...

  8. 使用AJAX传输不了值时

    当时候AJAX往后台传递值时  传不到后台  这时我们就要检查程序是否有问题了 一般AJAX程序 $.ajax( { type: "POST", url: "Login. ...

  9. GreenPlum 数据库启动关闭及数据库状态检查

    本篇文章主要记录GreenPlum数据库的启动.关闭及状态查询.GreenPlum数据库提供gpstart和gpstop脚本来启动和关闭数据库,可以通过—help参数来查看这些脚本的帮助信息. vie ...

  10. 十.iSCSI网络磁盘

    默认端口:3260 • Internet SCSI,网际SCSI接口 – 一种基于C/S架构的虚拟磁盘技术 – 服务器提供磁盘空间,客户机连接并当成本地磁盘使用   • backstore,后端存储 ...