V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
wenfan
V2EX  ›  Google

Google 地图 字体 API 反代

  •  
  •   wenfan · 2017-07-24 13:29:54 +08:00 · 2189 次点击
    这是一个创建于 2430 天前的主题,其中的信息可能已经有所发展或是发生改变。
    由于 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>
    11 条回复    2020-10-17 04:32:09 +08:00
    wenfan
        1
    wenfan  
    OP
       2017-07-24 13:41:59 +08:00
    proxy.conf 修改后 请重启 Apache 服务让设置生效。

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

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

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

    更换了域名,新的地址为:
    https://fonts.wen.fan/css?family=Roboto
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5559 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 05:57 · PVG 13:57 · LAX 22:57 · JFK 01:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.