Nginx代理配置只允许指定IP访问
source link: https://blog.51cto.com/u_15430445/5996775
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Nginx代理配置只允许指定IP访问
精选 原创在使用Nginx时,有时只想要指定的IP进行访问,其余IP都需要禁止,今天就来说一下,Nginx如何配置允许、禁止指定Ip访问
index index.jsp;
proxy_next_upstream http_500 http_502 http_503 http_504 error timeout invalid_header;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
deny 192.168.1.1;
allow 127.0.0.0/50;
allow 173.56.0.0/25;
allow 132.16.0.0/25;
allow 12.170.0.0/25;
deny all;
}
注意事项:
1. deny
一定要加一个ip,否则直接跳转到403,不往下执行了;如果403默认页是同一域名下,会造成死循环访问;
2. allow的ip段
从允许访问的段位从小到大排列,如:127.0.0.0/50
下面才能是:12.170.0.0/25
24表示子网掩码:255.255.255.0
16表示子网掩码:255.255.0.0
8表示子网掩码:255.0.0.0
3. deny all;结尾
表示除了上面allow的其他都禁止
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK