PM2下使用 npm run 命令

需求: npm run xxxx 是 node常用的启动方式之一,本文介绍下如何用PM2来实现该方式的启动。 下面是项目的package.json文件部分代码: scripts: { dev: node build/dev-server.js --env=local, start: node build/dev-server.js --env=local, build: node build/build.js --env=publish, build-local: node build/
分类至 JS
0条评论

禁止国外ip访问服务器,屏蔽国外ip访问网站代码

如果能屏蔽国内ip访问网站,能干掉70%的CC或者ddos攻击,我用的是CentOS先运行如下语句获取国内IP网段,保存到此目录下:root/china_ssr.txt

wget -q --timeout=60 -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | awk -F\| '/CN\|ipv4/ { printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > /root/china_ssr.txt
将下面脚本保存为/root/allcn.sh ,设置可执行权限

mmode=$1
 
#下面语句可以单独执行,不需要每次执行都获取网段表
#wget -q --timeout=60 -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | awk -F\| '/CN\|ipv4/ { printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > /root/china_ssr.txt
 
CNIP="/root/china_ssr.txt"
 
 
gen_iplist() {
        cat <<-EOF
                $(cat ${CNIP:=/dev/null} 2>/dev/null)
EOF
}
 
flush_r() {
iptables  -F ALLCNRULE 2>/dev/null
iptables -D INPUT -p tcp -j ALLCNRULE 2>/dev/null
iptables  -X ALLCNRULE 2>/dev/null
ipset -X allcn 2>/dev/null
}
 
mstart() {
ipset create allcn hash:net 2>/dev/null
ipset -! -R <<-EOF 
$(gen_iplist | sed -e "s/^/add allcn /")
EOF
 
iptables -N ALLCNRULE 
iptables -I INPUT -p tcp -j ALLCNRULE 
iptables -A ALLCNRULE -s 127.0.0.0/8 -j RETURN
iptables -A ALLCNRULE -s 169.254.0.0/16 -j RETURN
iptables -A ALLCNRULE -s 224.0.0.0/4 -j RETURN
iptables -A ALLCNRULE -s 255.255.255.255 -j RETURN
#可在此增加你的公网网段,避免调试ipset时出现自己无法访问的情况
 
iptables -A ALLCNRULE -m set --match-set allcn  src -j RETURN 
iptables -A ALLCNRULE -p tcp -j DROP 
 
 
}
 
if [ "$mmode" == "stop" ] ;then
flush_r
exit 0
fi
 
flush_r
sleep 1
mstart
执行下面代码,执行后国外ip将无法打开网站

/root/allcn.sh
如果要停止的话执行下面这个命令可恢复国外ip访问网站:

/root/allcn.sh stop
注意:代码是建立在你懂脚本命令的情况下,新手小白不要瞎搞

 

分类至 Linux
0条评论