Google 地图 字体 API 反代

2017-07-24 13:29:54 +08:00
 wenfan
由于 BAIDU 地图实在恶心,但是 Google 地图 api 在国内又非常不稳定,而 ditu.google.cn 这个 api 又不提供 HTTPS。在网上找了很久,反代 Google 的方法很多,但是反代 Google API 尤其是地图 API 的。之前发现了一个南阳 GDG 提供的 API 服务( https://ditu.gdgdocs.org/maps/api/js?sensor=false ),但是仿佛最近也被盯上了,http://www.gdgny.org/ 本身已无法访问。

于是,只能自己动手丰衣足食。提供给有需要的人士使用,但是请勿滥用。。。

使用方法 Usage:

替换谷歌字体 API:

https://fonts.googleapis.com/css?family=Roboto
替换成
https://fonts.wenfan.cn/css?family=Roboto


替换谷歌地图 API:

https://maps.google.com/maps/api/js?key=YOURKEY
替换成
https://maps.wenfan.cn/maps/api/js?key=YOURKEY

详见: https://wenfan.cn/archives/2408.wen

用自己服务器做 GMAP API 反代的方法:
1、设定 mapsapis.YOURNAME.COM 的 A 记录指向 Host IP (一定要是 mapsapis 这个 subdomain)
2、进入 etc/apache2/mods-enabled/proxy.conf
3、在 proxy.conf 设置如下:

<IfModule mod_proxy.c>
RequestHeader unset Accept-Encoding
SSLProxyEngine On
SSLProxyCheckPeerCN on
ProxyPass /g_www/ https://google.com/
ProxyPassReverse /g_www/ https://google.com/
ProxyPass /g_mts0/ https://mts0.googleapis.com/
ProxyPassReverse /g_mts0/ https://mts0.googleapis.com/
ProxyPass /g_mts1/ https://mts1.googleapis.com/
ProxyPassReverse /g_mts1/ https://mts1.googleapis.com/
ProxyPass /g_maps/ https://maps.gstatic.com/
ProxyPassReverse /g_maps/ https://maps.gstatic.com/
ProxyPass /g_csi/ https://csi.gstatic.com/
ProxyPassReverse /g_csi/ https://csi.gstatic.com/
ProxyPass /g_gmaps/ https://maps.googleapis.com/
ProxyPassReverse /g_gmaps/ https://maps.googleapis.com/
ProxyPass /g_googlemaps/ https://maps.google.com/
ProxyPassReverse /g_googlemaps/ https://maps.google.com/
ProxyPass /maps/ https://maps.googleapis.com/maps/
ProxyPassReverse /maps/ https://maps.googleapis.com/maps/


Substitute "s|mts0.googleapis.com|YOURNAME.COM/g_mts0|n"
Substitute "s|mts1.googleapis.com|YOURNAME.COM/g_mts1|n"
Substitute "s|maps.gstatic.com|YOURNAME.COM/g_maps|n"
Substitute "s|csi.gstatic.com|YOURNAME.COM/g_csi|n"
Substitute "s|maps.googleapis.com|mapsapis.YOURNAME.COM|n"
Substitute "s|maps.google.com|YOURNAME.COM/g_googlemaps|n"
Substitute "s|https://google.com|https://YOURNAME.COM/g_www|n"
FilterDeclare Substitute
FilterProvider Substitute SUBSTITUTE "%{REQUEST_URI} =~ m#^/#"
FilterChain +Substitute
</IfModule>
2231 次点击
所在节点    Google
11 条回复
wenfan
2017-07-24 13:41:59 +08:00
proxy.conf 修改后 请重启 Apache 服务让设置生效。

sudo restart apache2
a2213108
2017-07-24 18:00:49 +08:00
https://maps.google.cn/maps/api/js?key=
我这边能打开,不知道能不能正常用
a2213108
2017-07-24 18:03:31 +08:00
另外 https://fonts.googleapis.com 谷歌有做国内解析到北京服务器,应该不用反代
wenfan
2017-07-24 18:20:06 +08:00
@a2213108 谢谢提醒!主要是从稳定性考虑的,毕竟每年有那么多会要开。。。算是一个 backup option 吧
nicoljiang
2017-07-26 18:14:02 +08:00
反代多了,小心把你 IP 封了。
chenglu
2017-07-27 08:08:41 +08:00
服务还在,本人不再做 GDG 社区了,所以目前是准备找个开源组织接手,也没有被盯上哈~

这些服务也只是之前办活动时候方便大家写一些代码演示,体验谷歌的技术产品,所以也没有完全反代,也没有特别高调公开。
wenfan
2017-07-28 09:00:00 +08:00
@chenglu 大神出现了!我还特别担心 这么良心的服务 是不是被组织盯上了。平安就好!
wenfan
2017-07-28 09:03:07 +08:00
@chenglu 顺便问一下 mapsapis 那个地方 为什么一定要用 mapsapis 这个子域名?其他资源都可以直接以 yourname.com/xxxx 的方式直接代替,但是唯独这个不可以。If not, then 会提示 The Google Maps JavaScript API must be downloaded directly from Google's servers
chenglu
2017-07-28 11:36:28 +08:00
@wenfan 可能谷歌的这些前端资源服务器会做一些域名的验证,我其实是用子域名的方式替换掉这些资源的,或许这些无关?你试试传一个 Google 域名的 header 过去看看是否可以。

低调传播,仅作研究用途就好,没关系的 :-)
wyds591101
2018-07-25 09:27:16 +08:00
在用 非常稳定 就不自己搭建了。服务器不如楼主的快。
wenfan
2020-10-17 04:32:09 +08:00
Update in 2020:

更换了域名,新的地址为:
https://fonts.wen.fan/css?family=Roboto

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/377525

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX