nginx防盗链配置

nginx防盗链配置的代码,默认跳转404页面,可配置跳转图片。

#SECURITY-START 防盗链配置
location ~ .*\.(jpg|jpeg|gif|png|js|css)$
{
    expires      30d;
    access_log /dev/null;
    valid_referers none blocked *.tanst.net www.tanst.net;
    if ($invalid_referer){
       #rewrite ^/ http://ww4.sinaimg.cn/bmiddle/051bbed1gw1egjc4xl7srj20cm08aaa6.jpg;
       return 404;
    }
}
#SECURITY-END

shell多条件逻辑判断

用括号分隔,例子:

#!/bin/bash

a=asdf
b=23rr
c=23fsd
d=j32l4
e=j123
f=123

# a=asdf b=23r2r c=23fsdf e=j123 or j456
# or
# d=j32l4 f=123

if ([ $a = 3434sdf ] && [ $b = 23rr ] && [ $c = 23fsd ] && ([ $e = j123 ] || [ $e = j456 ])) || ([ $d = j32l4 ] && [ $f = 123 ])

then
   echo "执行"
else
   echo "不执行"
fi

shell 自动计算 bytes KB MB

自动计算 bytes 为 KB、MB、GB、TB,代码分2种,一种显示整数,一种显示2位小数。

#!/bin/sh
human_bytes(){
while read B dummy; do
  [ $B -lt 1024 ] && echo ${B} Bytes && break
  KB=$(((B+512)/1024))
  [ $KB -lt 1024 ] && echo ${KB} KiB && break
  MB=$(((KB+512)/1024))
  [ $MB -lt 1024 ] && echo ${MB} MiB && break
  GB=$(((MB+512)/1024))
  [ $GB -lt 1024 ] && echo ${GB} GiB && break
  echo $(((GB+512)/1024)) TiB
done
}

human_bytes_2(){
while read B dummy; do
  [ $B -lt 1024 ] && echo ${B} Bytes && break
  KB=$(echo "scale = 2; $B/1024" | bc | awk '{printf "%.2f", $0}')
  [ $(echo "$KB > 1024" | bc) -eq 0 ] && echo ${KB} KiB && break
  
  MB=$(echo "scale = 2; $KB/1024" | bc | awk '{printf "%.2f", $0}')
  [ $(echo "$MB > 1024" | bc) -eq 0 ] && echo ${MB} MiB && break
  
  GB=$(echo "scale = 2; $MB/1024" | bc | awk '{printf "%.2f", $0}')
  [ $(echo "$GB > 1024" | bc) -eq 0 ] && echo ${GB} GiB && break
  
  echo $(echo "scale = 2; $GB/1024" | bc | awk '{printf "%.2f", $0}') TiB
done
}

Proxmox VE单网卡多IP配置

Proxmox VE基于debian的,所以直接改/etc/network/interfaces文件,用service networking restart命令重启网络不用重启机器,如果用webui改会锁定配置文件,生成一个interfaces.new文件,重启机器才能生效。

auto lo eth0
iface lo inet loopback
iface eth0 inet manual

auto vmbr0
iface vmbr0 inet static
        address 118.7.34.69
        netmask 255.255.255.0
        gateway 118.7.34.1
        bridge_ports eth0
        bridge_stp off
        bridge_fd 0
iface vmbr0 inet6 static
    address  2f02:0190:0006:0001:0000:0000:0000:0844
    netmask  64
    gateway  2f02:0190:0006:0001:0000:0000:0000:0001

此方法适合安装好Proxmox VE没有自动生成vmr0的情况,需要手动添加vmr0虚机交换机,重点是把原网卡eth0改成manual,vmr0的IP改成物理IP,虚拟机直接填外网IP即可。