ubuntu16.04搭建Google镜像站
这篇文章主要记录下自己搭建Google镜像站的一些经验。在刚开始搭建的时候,参考网上的一些文章后遇到了很多坑,所以这里详细记录下自己搭建的过程。
介绍
有了cuber大神的ngx_http_google_filter_module Nginx插件之后,让我们能很轻易地搭建自己的Google镜像站,项目介绍得很清楚。
ngx_http_google_filter_module
is a filter module which makes google mirror much easier to deploy.
Regular expressions, uri locations and other complex configurations have been built-in already.
The native nginx module ensure the efficiency of handling cookies, gstatic scoures and redirections.
搭建过程
项目介绍有两种安装方式:
* 简易安装
* 从发行版迁移
其中的区别就是(我的理解)当你的服务器已经安装了Nginx并且已经代理了你的其它站点的话,用第二种方法比较方便一点,不用改变你之前的所有配置项。
这里用第二种方式实现。
安装过程
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# 安装 gcc & git apt-get install build-essential git gcc g++ make # 安装发行版 # (已安装的请忽略) apt-get install nginx # 查看发行版编译选项及版本 # nginx -v # nginx version: nginx/1.10.3 # 下载对应 nginx 版本 # nginx 官网: # http://nginx.org/en/download.html wget "http://nginx.org/download/nginx-1.10.3.tar.gz" # 下载ngx_http_google_filter_module # 没有安装git的先安装git # sudo apt-get install git git clone https://github.com/cuber/ngx_http_google_filter_module # 下载 substitutions 扩展 git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module # 安装依赖库的 dev 包 apt-get install libpcre3-dev libssl-dev zlib1g-dev libxslt1-dev libgd-dev libgeoip-dev # 解压刚才下载的nginx压缩包 tar -xzf nginx-1.10.3.tar.gz # 进入nginx的目录 cd nginx-1.10.3 # 请对照自己发行版的 configure 参数进行 configure(ubuntu 16.04可用) ./configure \ --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' \ --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' \ --prefix=/usr/share/nginx \ --conf-path=/etc/nginx/nginx.conf \ --http-log-path=/var/log/nginx/access.log \ --error-log-path=/var/log/nginx/error.log \ --lock-path=/var/lock/nginx.lock \ --pid-path=/run/nginx.pid \ --http-client-body-temp-path=/var/lib/nginx/body \ --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \ --http-proxy-temp-path=/var/lib/nginx/proxy \ --http-scgi-temp-path=/var/lib/nginx/scgi \ --http-uwsgi-temp-path=/var/lib/nginx/uwsgi \ --with-debug \ --with-pcre-jit \ --with-ipv6 \ --with-http_ssl_module \ --with-http_stub_status_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_dav_module \ --with-http_geoip_module \ --with-http_gzip_static_module \ --with-http_image_filter_module \ --with-http_sub_module \ --with-http_xslt_module \ --with-mail \ --with-mail_ssl_module \ --add-module=../ngx_http_google_filter_module \ --add-module=../ngx_http_substitutions_filter_module #编译 make make install # 覆盖二进制文件 cp -rf objs/nginx /usr/sbin/nginx # 进行nginx的配置,请看后面 # 配置完成后重启nginx服务 sudo service nginx restart # 完成 |
Nginx配置项
nginx的配置文件在/etc/nginx/sites-enabled
中,可以自己新建一个google.conf
将下面的配置项填上去。
http配置
1 2 3 4 5 6 7 8 9 10 |
server { server_name google.ioiogoo.cn(你的域名); listen 80; resolver 8.8.8.8; location / { google on; } } |
https配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
server { server_name google.ioiogoo.cn(你的域名); listen 443; ssl on; ssl_certificate <你的证书>; ssl_certificate_key <你的私钥>; resolver 8.8.8.8; location / { google on; } } |
如果需要强制使用https的话在80端口将http重定向到https就行了。
1 2 3 4 5 6 |
server { server_name google.ioiogoo.cn; listen 80; rewrite ^(.*) https://google.ioiogoo.cn$1 permanent; } |
证书可以自己去申请,网上很多免费的ssl证书,腾讯云和阿里云都支持申请免费证书了。
参考资料
链接:https://www.ioiogoo.cn/2017/09/01/ubuntu16-04搭建google镜像站/
本站所有文章除特殊说明外均为原创,转载请注明出处!