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

发布了24 篇原创文章 · 获赞 1 · 访问量 4150

猜你喜欢

转载自blog.csdn.net/xiegan110/article/details/105326791