wenfan
V2EX  ›  Google

Google 地图 字体 API 反代

  •  
  •   wenfan · Jul 24, 2017 · 3280 views
    This topic created in 3239 days ago, the information mentioned may be changed or developed.
    由于 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 replies    2020-10-17 04:32:09 +08:00
    wenfan
        1
    wenfan  
    OP
       Jul 24, 2017
    proxy.conf 修改后 请重启 Apache 服务让设置生效。

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

    这些服务也只是之前办活动时候方便大家写一些代码演示,体验谷歌的技术产品,所以也没有完全反代,也没有特别高调公开。
    wenfan
        7
    wenfan  
    OP
       Jul 28, 2017
    @chenglu 大神出现了!我还特别担心 这么良心的服务 是不是被组织盯上了。平安就好!
    wenfan
        8
    wenfan  
    OP
       Jul 28, 2017   ❤️ 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  
       Jul 28, 2017 via Android
    @wenfan 可能谷歌的这些前端资源服务器会做一些域名的验证,我其实是用子域名的方式替换掉这些资源的,或许这些无关?你试试传一个 Google 域名的 header 过去看看是否可以。

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

    更换了域名,新的地址为:
    https://fonts.wen.fan/css?family=Roboto
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1135 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 18:06 · PVG 02:06 · LAX 11:06 · JFK 14:06
    ♥ Do have faith in what you're doing.