iT邦幫忙

2021 iThome 鐵人賽

DAY 15
0
DevOps

和 gitlab 一起當個好朋友系列 第 15

Day15-Nginx 限制訪問來源

Nginx

直接寫在 config 內

location / {
allow 127.0.0.0/24;
allow 192.168.0.0/16;
allow 10.10.0.0/16;

deny all;

root /var/www/html/;
index index.php;
}
  • deny - 拒絕連線的 ip
  • allow - 允許連線的 ip
  • deny all - 拒絕所有的連線

上方的設定會是 允許 allow 的 ip
其他的所有 ip 都拒絕

設定檔

但是如果越來越多的時候

可以改由設定檔

  $ vim /etc/nginx/conf/example1.conf

example1.conf

deny 192.168.1.1;
allow 127.0.0.0/24;
allow 192.168.0.0/16;
allow 10.10.0.0/16;

deny all;

接下來只在需要的地方 include 進設定檔即可

xxx.nginx.config

location / {

#只允許內部訪問IP清單
include conf/Internal_acc.conf

root /var/www/html/;
index index.php;
}

這樣就可以做一些設定限制

提高服務的安全性


上一篇
Day14-Load Balance
系列文
和 gitlab 一起當個好朋友15
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言