nginx白名单基于ip的设置

这个在nginx反代服务器进行设置,一般不对所有人开放的东西我们是需要设置ip的白名单的。比如:后面的数据统计,是需要对内部人员开放的
1.首先反代nginx配置转发
upstream api{
server 192.168.76.17:80;
}

server {
listen 80;
server_name houtai.com;
#rewrite ^(.*)$ https://$host$1 permanent;
include vhost/houtai/gm_ip.list; 这里是设置用户80访问的白名单
location / {
proxy_pass http://api/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;
}
}

server {
listen 443 ssl;
server_name houtai.com;
ssl_certificate /data/ssl/panda.crt;
ssl_certificate_key /data/ssl/panda.key;
include vhost/houtai/gm_ip.list; 这设置的就是443白名单
location / {
proxy_pass http://api/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;
}
}

2.现在我们在反代在配置白名单的配置文件
if ($http_x_real_ip !~ “22.22.22.22|11.11.11.11”) {
return 302 https://ifconfig.me; #这里设置的意思是如果来访的ip不是在这里的,我们会设置临时跳转到这个网址,查询你自己的ip是多少;也可以设置301。
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值