-
-
Save mrichie/1436897 to your computer and use it in GitHub Desktop.
Nginx http proxy cache to mirror of Rubygems.org
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 在本地服务器建立 rubygems.org 的镜像缓存,以提高 gem 的安装速度 | |
# 此配置设置缓存过期为1天,也就是说,新上的 gem 无法马上安装 | |
# 做这个起什么作用? | |
# rubygems 的很多资源文件是存放到 Amazon S3 上面的,由于 GFW 对某些 S3 服务器又连接重置或丢包,导致 gem 安装异常缓慢或有时候根本无法连接安装。 | |
# 而通过这种跳板的方式可以很好的解决这个问题,当然前提是 Nginx反向代理 服务器需要在国外 | |
proxy_cache_path /var/cache/rubygems levels=1:2 keys_zone=RUBYGEMS:10m | |
inactive=24h max_size=1g; | |
server { | |
listen 80; | |
server_name rubygems.org; | |
location / { | |
proxy_pass http://rubygems.org; | |
proxy_redirect off; | |
proxy_set_header Host $http_host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
} | |
server { | |
listen 80; | |
server_name production.cf.rubygems.org; | |
location / { | |
proxy_pass http://production.cf.rubygems.org; | |
proxy_redirect off; | |
proxy_set_header Host $http_host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_cache RUBYGEMS; | |
proxy_cache_valid 200 1d; | |
proxy_cache_use_stale error timeout invalid_header updating | |
http_500 http_502 http_503 http_504; | |
} | |
} | |
server { | |
listen 80; | |
server_name production.s3.rubygems.org; | |
location / { | |
proxy_pass http://production.s3.rubygems.org; | |
proxy_redirect off; | |
proxy_set_header Host $http_host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_cache RUBYGEMS; | |
proxy_cache_valid 200 1d; | |
proxy_cache_use_stale error timeout invalid_header updating | |
http_500 http_502 http_503 http_504; | |
} | |
} | |
server { | |
listen 443; | |
server_name rubygems.org; | |
location / { | |
proxy_pass https://rubygems.org; | |
proxy_redirect off; | |
proxy_set_header Host $http_host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
ssl on; | |
ssl_certificate /etc/nginx/conf/server.crt; | |
ssl_certificate_key /etc/nginx/conf/server.key; | |
ssl_session_timeout 5m; | |
ssl_protocols SSLv2 SSLv3 TLSv1; | |
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; | |
ssl_prefer_server_ciphers on; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ vi /etc/hosts | |
your.ip.add.ress rubygems.org | |
your.ip.add.ress production.cf.rubygems.org | |
your.ip.add.ress production.s3.rubygems.org |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment