zmirror
an http reverse proxy designed to automatically and completely mirror a website (such as google), support cache and CDN
一个Python反向HTTP代理程序, 用于快速、简单地创建别的网站的镜像, 自带本地文件缓存、CDN支持
比如国内可以访问的Google镜像/中文维基镜像
自带了几个配置文件: 比如 Google镜像(含学术/其他/中文维基) twitter镜像 Youtube镜像 instagram镜像 Facebook镜像
完整列表请看zmirror自带镜像配置文件
请在遵守当地相关法律法规的前提下使用本项目
本人拒绝为任何商业或非法目的提供任何技术支持
本项目仅为科研人员更方便地查询知识而创建, 请勿大范围传播
若想看代码, 请看 v0.30-dev
这个分支
请不要大量使用...demo服务器马上要爆炸了- -|
Demo
-
Google
- 网页搜索 https://g.zmirrordemo.com
- Scholar https://g.zmirrordemo.com/scholar
- Image https://g.zmirrordemo.com/imghp
- Gmail https://g.zmirrordemo.com/gmail (请选择"使用基本HTML"版本)
-
中文维基
- (PC & Mobile) https://g.zmirrordemo.com/wiki
-
Youtube
- PC Only https://ytb-pc.zmirrordemo.com
Youtube访问需要密码, 请解密此串得到密码WmhlamlhbmdVbml2ZXJzaXR5
如果您无法解密, 很抱歉Youtube镜像不对您开放 - Mobile Only
https://ytb-mobile.zmirrordemo.com暂不开放
Youtube Mobile 不支持iOS
- PC Only https://ytb-pc.zmirrordemo.com
-
Twitter
- PC Only https://t-pc.zmirrordemo.com
- Mobile Only https://t-mobile.zmirrordemo.com
-
Instagram
- PC & Mobile https://in.zmirrordemo.com
-
Facebook
- PC Only https://fb.zmirrordemo.com
绝大部分功能可用, 但是不完整
- PC Only https://fb.zmirrordemo.com
Screenshot
More screenshots are here: wiki-screenshots
一键部署脚本
https://github.com/aploium/zmirror-onekey
一键部署脚本仍然不稳定, 如果怎么弄都失败, 请看手动教程
builtin configs
Together with the program, provided several (almost) out-of-box configs
Google镜像 (整合中文维基镜像)
- Gmail支持! (请访问 /gmail 并选择基础html视图)
- 同时支持PC/手机
- Google搜索与中文维基百科无缝结合
- 大部分功能完全正常: 网页搜索/学术/图片/地图/新闻/图书/视频(搜索)/财经/APP搜索/翻译/网页快照/...
- 目前暂时无法做到完美的登陆, 登录才可使用的功能部分无效
- 不会被Google Ban掉
传统的Nginx反代Google方案, 时间长了会被Google Ban掉, 或者弹图片验证码,
这是由于Nginx反代镜像非常简陋, 用户的许多请求无法被正确发回到Google服务器,
Google就会把真实的访问者当成是机器人.
而zmirror比较完善, 用户的请求能全部发回到Google服务器, 不会被当成机器人
Twitter镜像
- 支持PC站/手机 (两者需要以不同的域名部署, 详见配置)
- 几乎所有功能完整可用, 大部分视频可以播放
Instagram镜像
- 所有功能完整可用, 包括视频
Youtube镜像
- 支持PC站/手机 (两者需要以不同的域名部署, 详见配置)
- 视频播放、高清支持
- 登陆支持、字幕支持
- 小视频上传支持
Facebook镜像
- 绝大部分功能可用, 但是不完整
自带其他的镜像配置文件
- archive.org镜像
- duckduckgo镜像
- Dropbox镜像
- Tumblr镜像
- Economist(经济学人)镜像
- thepiratebay(海盗湾)镜像
- For more information, please see more_configs/readme.md
Requirements Install and Usage
Dependencies
Required
Optional
- cChardet 编码检测
- fastcache C implementation of Python 3 lru_cache
- lru-dict A fast and memory efficient LRU dict for Python
Theoretically, any environment that can run Python3.4+, can also run zmirror
Nginx was not officially tested, but it should work pretty well.
However, due to my limited time, zmirror was only fully tested in:
Ubuntu14.04-x86_64 Apache2.4 wsgi python3.4
Ubuntu16.04-x86_64 Apache2.4 wsgi python3.5
windows10-x64 Apache2.4 wsgi python3.5-x64
Ubuntu14.04-x86_64 directly run (I mean, just execute python3 wsgi.py)
windows10-x64 directly run
Installation and helloworld
This tutorial is mainly for your localhost demo test
If you want to deploy it to server, please complete the localhost demo first
-
first, install python3
Debian/Ubuntuapt-get install python3
Windows go to python's homepage and download Python3.5 (or newer) -
install or upgrade flask and requests
python3 -m pip install -U flask requests
-
git clone https://github.com/aploium/zmirror
-
copy the
config_default.py
toconfig.py
Warning: You should NEVER EVER modify the
config_default.py
itself
Please edit theconfig.py
instead ofconfig_default.py
Unless your are developer.
Settings in theconfig.py
would override the default ones -
Execute it:
python3 wsgi.py
-
Open your browser and enter
http://127.0.0.1/
, you will see exactly thewww.kernel.org
, and you can click and browse around. everything of the*.kernel.org
is withing the mirror. -
please see the following Deploy section
Deploy
请使用: 一键部署脚本
若希望手工部署, 可以看以下教程:
在Nginx下部署, 请看这里(感谢@phuslu)
Or, if you are familiar with flask, you can see flask's official deploy tutorial
Upgrade
-
cd YOUR_ZMIRROR_FOLDER
and thengit pull
警告
由于 v0.27 有很大的结构改动, 所以 v0.27 以内的 custom_func.py 如果有from zmirror import
语句
将无法在 v0.27 以后的版本工作
解决办法是将 custom_func.py 中的from zmirror import
修改为
from zmirror.zmirror import
其他不需要改变
若使用自带配置文件, 则只有Youtube和Twitter受影响
Feature
-
Completely mirror, provide some (almost) out-of-box configs
创建非常完整的镜像, 既支持古老的网站(比如内网网站), 也支持巨型的现代化的网站
提供几个(几乎)开箱即用的网站镜像配置文件 -
Mirror ANY website, highly compatible
非常高的兼容性和通用性, 可以镜像 任意 网站, 而不只是Google/Wiki/twitter/instagram, 而且功能都非常完整
并且能很好地适应对现代化的、逻辑复杂、功能庞大的网站
现在还在开发阶段, 虽然所有网站的绝大部分功能都可以开箱即用, 但是某些网站的某些功能仍然不完整, 正在不断改进 -
(MIME-based) Local statistic file cache support (especially useful if we have low bandwidth or high latency)
(基于MIME)本地静态文件缓存支持(当镜像服务器与被镜像服务器之间带宽很小或延迟很大时非常有用) -
CDN Support, hot statistic resource can serve by CDN, dramatically increase speed
CDN支持. 让热门静态资源走CDN, 极大提高用户访问速度(特别是使用国内CDN, 而镜像服务器在国外时) -
Easy to config and deploy, highly automatic
非常容易配置和部署, 镜像一个网站只需要添加它的域名即可 -
Access control(IP, user-agent), visitor verification(question answer, or custom verification function)
访问控制(IP, user-agent)与用户验证(回答问题, 也支持写自定义的验证函数) -
Automatically rewrite JSON/javascript/html/css, even dynamically generated url can ALSO be handled correctly
自动重写JSON/javascript/html/css中链接, 甚至即使是动态生成的链接, 都能被正确处理 -
Stream content support (audio/video)
流媒体支持(视频/音频)
Issues Report
非常欢迎发issues, 发issues找我聊天都欢迎.
对于Apache(教程部署的即为Apache), 程序的日志在 /var/log/apache2/你自定义的日志文件名_error.log
中
(以下只是可选步骤)
Report zmirror Internal Error
当zmirror发生内部错误时(浏览器看到一个Internal Error页面), zmirror会把当前状态的快照保存到 zmirror安装目录/error_dump/
中
可以使用pickle来读取其中的dump文件.
如果存在对应的dump文件, 请在issues中附上
Mirror A Website
本部分需要重写, 写的很乱, 也有点过时了 Mirror a website is very simple.
Just set the target_domain
to it's domain, the external_domains
to it's external domain and sub domains such as static resource domains (If it has)
save and run, the program will do the other works!
All detects and rewrites are completely AUTOMATICALLY
tips:
you can find a website's external domains by using the developer tools of your browser, it will log all network traffics for you
Performance Enhance
Local Cache
Local file cache (along with 304 support) is implanted and enabled by default
If cache hits, you will see an x-zmirror-cache: FileHit
in the response header.
Local cache will be deleted and cleaned once program exit.
CDN Support
please see 使用七牛作为zmirror镜像的CDN
zmirror 一键部署脚本
使用zmirror快速部署镜像的脚本
如果无法部署成功, 可以尝试手动部署: 手动部署zmirror
或尝试由yumin9822提供的脚本
前置需求
-
一台墙外VPS, OpenVZ/Xen/KVM均可
-
操作系统:
- 支持的操作系统:
- Ubuntu 14.04/15.04(不支持HTTP2)/15.10/16.04+
- Debian 8 (不支持HTTP/2)
- 不支持 CentOS/RHEL/Windows/Fedora/Arch/... 对于这些系统, 可以使用由yumin9822提供的这个脚本
- 推荐的操作系统:
- Ubuntu 16.04 x86_64
- 全新(刚安装完成)的操作系统. 如果系统中有其他东西, 可能会产生冲突
- root权限
- 支持的操作系统:
-
域名
- 每个镜像要求一个三级域名(类似于
g.zmirrordemo.com
这样的, 有三部分, 两个点) - 域名已经在DNS记录中正确指向你的VPS
提示
如果你没有自己的域名, 请看FAQ-我没有自己的域名 - 每个镜像要求一个三级域名(类似于
运行方法
-
我没有SSL证书 (如果不懂, 请使用这个)
sudo apt-get -y update && sudo apt-get -y install python3 git git clone https://github.com/aploium/zmirror-onekey.git --depth=1 cd zmirror-onekey sudo python3 deploy.py
然后按照脚本给予的提示继续, 过程中会自动获取SSL证书
如果有不懂的, 可参考下面的安装视频
如果遇到bug, 请发issues提出 -
我已有SSL证书
如果已有证书, 希望使用自己提供的证书, 而不是通过 let's encrypt 获取
请将上面代码中的第四行替换成下面的样子, 在运行期间会提示你输入证书路径的:sudo python3 deploy.py --i-have-cert
警告
不支持加密的私钥, 如果私钥有密码加密, 请先解密
安装过程视频
特性
- 支持一次部署多个镜像, 支持同VPS多镜像
- 自动安装 let's encrypt 并申请证书, 启用HTTPS
- 自动添加 let's encrypt 的定期renew脚本到crontab
- 启用HTTP/2 ps:Debian8和Ubuntu15.04不支持HTTP/2
- 启用HSTS
FAQ
-
有没有部署完成的Demo?
当然有, 请戳 zmirror-demo
-
我没有自己的域名
有一些提供免费(也没有注册门槛)域名的注册商
比如最有名的 .tk 域名
可以快速注册免费的域名注意
请不要使用 .cf 和 .ga 域名, letsencrypt对它们的支持非常差, 经常出现无法下发证书的问题
除非不得已, 在使用免费域名时, 请使用老牌的 .tk 域名 -
安装完成后各个程序的文件夹在哪?
-
zmirror
安装在/var/www/镜像名
文件夹下
镜像名为每个镜像的名字, 比如YoutubePC就是/var/www/youtubePC
-
let's encrypt
本体在:/etc/certbot/
申请到的证书位置, 请看 certbot文档-where-are-my-certificates -
Apache
Apache的配置文件在/etc/apache2/
下
其中各个站点的配置文件在/etc/apache2/sites-enabled/
Apache日志文件在
/var/log/apache2/镜像名_后缀.log
后缀为 _error 的日志文件中, 同时包含了stdout的输出(无论是否是错误), 对debug会有帮助
-
-
为什么安装的是Apache, 而不是Nginx, 我可以选择吗?
因为Apache的wsgi对python更友好
而且Nginx没有Visual Host功能
在性能上, 由于性能瓶颈是zmirror本身, 所以Apache和Nginx之间的性能差距可以被忽略目前一键脚本只能安装Apache, 不支持Nginx, 也没有支持Nginx的计划, 如果需要Nginx, 请手动部署
手动部署可以参考 zmirror wiki
当然, 如果你能写一份Nginx部署教程, 我会很感谢的~ :) -
安装的Apache版本?
在Ubuntu中, 使用的是 PPA:ondrej/apache2 理论上应该是最新版, 或者接近最新版(2.4.23+)
在Debian8中, 使用系统的 apt-get 安装, 版本比较旧, 所以Debian不支持HTTP/2 -
Let's encrypt 证书自动更新?
安装脚本会自动创建定期更新证书的脚本, 脚本位置为
/etc/cron.weekly/zmirror-letsencrypt-renew.sh
-
证书有效期为什么只有90天?
主要是因为Let's encrypt认为, 证书的申请和部署可以自动化时, 90天足够了.
具体可以看这个官方说明(可能需要自备梯子)
本安装脚本会在linux定时任务(crontab)中加入自动续期的脚本, 不用担心证书过期
即使自动续期脚本万一失效了, let's encrypt也会在快要过期时邮件通知你 -
其他高级功能, 比如说CDN, 在哪?
这个脚本只提供最基础的部署, 高级功能需要手动配置
请看config_default.py和custom_func.sample.py中的说明如果想用CDN, 可以看这个教程使用七牛作为zmirror镜像CDN
警告
如果你想要修改config_default.py
中的某项设置, 请不要直接修改
而应该将它复制到config.py
中, 然后修改config.py
里的设置
config.py
中的设置会覆盖掉config_default.py
中的同名设置
除非你是开发者, 否则无论如何都不应该修改config_default.py
-
网速太慢?
如果你的VPS提供商允许的话, 可以试试看net-speeder
或者换一个网速快的VPS, Demo站使用的VPS是Ramnode
服务器地点是LA(Los Angeles), 速度相当快.
ps: 如果你也想试试看的话, 请点击这个链接进入, 这里有我的推广小尾巴, 你买了的话我会有一丢丢(好像是10%)分成
ramnode允许使用net-speeder -
证书获取失败
脚本使用[Let's encrypt(certbot)](https://letsencrypt.org/)来获取证书
certbot 会在本地 Listen 80 或者 443 端口, 然后由远程授权服务器根据**域名的[A记录](https://support.dnspod.cn/Kb/showarticle/tsid/30/)**来**访问本机**
当远程服务器成功连接到本机的certbot客户端后, 就会颁发证书.
详细流程请看官方文档[How It Works](https://letsencrypt.org/how-it-works/)
证书获取失败最有可能的原因是域名记录设置后[尚未来得及生效](https://support.dnspod.cn/Kb/showarticle/tsid/53/), 域名DNS记录的生效通常需要数分钟以上, 最长可达*72小时*
对于这种情况, 除了等待以外是没有什么办法的.
本脚本在默认的5次尝试失败后, 会提示是否一直尝试下去, 如果你确认DNS记录已经正常设置, 请在提示
`max retries exceed, do you want to continue retry infinity?(Y/n)`
时, 选择Y, 一般数分钟内就能成功.
如果不能确定是否正常设置, 可以访问 https://www.whatsmydns.net/ , 这个网站可以在全球范围内查询A记录
如果查询出的A记录与你的IP相同, 就表示设置成功了, 此时只需要让脚本自行尝试即可
如果此时仍然多次尝试失败, 请看下面的`手动运行lets encrypt获取证书`部分
> **手动运行lets encrypt获取证书**
> 如果能确认DNS记录已经设置正常, 但是仍然无法获取证书, 请尝试手动运行letsencrypt获取证书:
>
> ```bash
> sudo service apache2 stop
> sudo /etc/certbot/certbot-auto certonly --standalone -d "你的域名1"
> sudo /etc/certbot/certbot-auto certonly --standalone -d "你的域名2"
> sudo service apache2 start
> ```
>
> 或者(如果上面的仍然失败)
> ```bash
> sudo apt-get install letsencrypt
> sudo service apache2 stop
> sudo letsencrypt certonly --standalone -d "你的域名1"
> sudo letsencrypt certonly --standalone -d "你的域名2"
> sudo service apache2 start
> ```
>
> 并在手动获取证书成功后再次运行本脚本
-
更新zmirror
请运行以下代码(假设
zmirror-onekey
是本脚本文件夹):cd zmirror-onekey git pull sudo python3 deploy.py --upgrade-only
注意: 更新zmirror以后会自动重启Apache
文章评论