根据IP选择ruby source

Posted

开发必备翻墙。但生产服务器是放在国内,那么问题就来啦!

Gemfile中的source写哪里的?

  source 'https://rubygems.org'
  source 'http://ruby.taobao.org'

切换国外的时候跑 https://rubygems.org

切换国内的时候跑 http://ruby.taobao.org

难道还要每次手工改不成?

在想能不能自动辨别!

  1. 不过也可vpn上做一个国内外分流 (不过当前不使用此方法)
  2. 自建源智能跳转 ruby.growcn.com

nginx中的配置 ruby_mirror.conf

geoip_country /usr/share/GeoIP/GeoIP.dat;
map $geoip_country_code $allow_visit {
  default other;
  CN cn;
}

server {
  server_name ruby.growcn.com;
  location ~ /\.git {
      deny  all;
  }

  if ($allow_visit = cn) {
    rewrite ^(.*) http://ruby.taobao.org$1 permanent;
  }

  if ($allow_visit = other) {
    rewrite ^(.*) https://rubygems.org$1 permanent;
  }
}

这时候: 国内IP打开 http://ruby.growcn.com 就到 http://ruby.taobao.org 国外IP打开 http://ruby.growcn.com 就到 https://rubygems.org

好!Gemfile可以写成

source 'http://ruby.growcn.com'

bundle

搞定!

参阅


此文章 短链接: http://dlj.bz/bcIx55