分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

反向代理Cloudflare加速网站(SNIproxy)

发布时间:2023-09-06 02:34责任编辑:沈小雨关键词:反向代理


写在教程前:为什么要反向代理cloudflare?答:缩短路由,加快cloudflare节点到大陆用户的速度,用过cloudflare的用户应该知道,这家CDN的速度在除了大陆以外的地方访问都非常快,那么又没有什么办法使其对大陆访问良好呢?
该操作适用环境:

①不想暴露源站,但是国内搜索引擎对cf节点抓取速度慢

②没被攻击前使用自建反代加快访问,宕机后迅速切换为cf官方节点(dnspod)

③没有使用NS接入而是CNAME

④有一台对国内访问快且访问Cloudflare也很快的服务器(如 PCCW、HKBN、TW中华电信、 bbtec)

反代程序有很多种,但是在这里我选用了SNI Proxy,为什么?因为Nginx等传统反代需要自行配置https证书,且无法如果CDN设置了强制https或重写https国内,将会出现跳转错误。

开始安装SNI Proxy

基本环境安装:

yum -y install tar wget && ??yum -y groupinstall "Development tools" && ??yum -y install pcre-devel pcre

安装辅助包libev4:

wget http://dist.schmorp.de/libev/Attic/libev-4.25.tar.gz && tar zxvf libev-4.25.tar.gz && cd libev-4.25 && ./configure -prefix=/usr/local/libev4 && ?make && ?make install

安装辅助包udns:

wget http://archive.ubuntu.com/ubuntu/pool/universe/u/udns/udns_0.4.orig.tar.gz ?&& tar zxvf udns_0.4.orig.tar.gz ?&& cd udns-0.4 ?&& ./configure ?&& ?makecd .. mv udns-0.4 /usr/local/udns

安装sniproxy:

wget https://down.cangshui.net/-mytargz/sniproxy.tar.gz && tar -zxvf sniproxy.tar.gz && sudo chmod -R 777 sniproxy && cd sniproxyexport CFLAGS='-I/usr/local/libev4/include -I/usr/local/udns' && export LDFLAGS='-L/usr/local/libev4/lib -L/usr/local/udns' && export LD_LIBRARY_PATH=/usr/local/libev4/lib:$LD_LIBRARY_PATH./autogen.sh./configure -prefix=/rootmakemake install

这样sniproxy就装到了/root/sbin/sniproxy,建立一个配置文件: vi /etc/sniproxy.conf 把一下内容编辑进去:

user nobodyresolver {nameserver 1.1.1.1 #指定NDSmode ipv4_only #只解析IPV4}listen 80 {proto httptable http_hostsaccess_log { ??filename /var/log/http_access.log ????priority notice ????}}table http_hosts {(.*.|)cangshui.net$ *#只允许自己的域名,改成自己的}listen 443 {proto tlstable https_hostsaccess_log { ??filename /var/log/https_access.log ????priority notice ????}}table https_hosts {(.*.|)cangshui.net$ *#只允许自己的域名,改成自己的}

启动SNIproxy:

/root/sbin/sniproxy -c /etc/sniproxy.conf

检查是否成功启动:

ps -ef | grep sniproxy

PS。记得iptables开放443/80端口:

iptables -I INPUT -p tcp --dport 443 -j ACCEPT iptables -I INPUT -p tcp --dport 80 -j ACCEPT

如何测试?本地修改HOST文件,windows端打开:

C:\Windows\System32\drivers\etc\hosts

然后写上:

你的反代服务器IP 你的域名如:68.68.68.68 lhzj.site

测试成功的话就可以解析到这个IP上了

需要注意的是:每次重启机器之后直接启动程序会报错

error while loading shared libraries: libev.so.4: cannot open shared object file: No such file or directory

你需要先执行

export LD_LIBRARY_PATH=/usr/local/libev4/lib:$LD_LIBRARY_PATH

然后再启动软件

反向代理Cloudflare加速网站(SNIproxy)

原文地址:https://www.cnblogs.com/L1079991001/p/10447728.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved