2025年3月31日 星期一 乙巳(蛇)年 正月初一 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 服务器 > 网络服务

ubuntu下用nginx搭建谷歌镜像网站

时间:10-29来源:作者:点击数:104

1. 介绍

很多 Google 镜像站用的工具是ngx_http_google_filter_module,是一个nginx的插件,用的原理是nginx的反向代理。

2. 编译安装

首先要有一台能访问google.com的vps或云主机,并且确保之前编译安装过nginx。

这个插件依赖于ngx_http_substitutions_filter_module这个库。

  • $ git clone https://github.com/cuber/ngx_http_google_filter_module
  • $ git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module
  • $ cd nginx
  • $ ./configure \
  • --user=nginx                   \
  • --group=nginx                   \
  • --prefix=/etc/nginx              \
  • --sbin-path=/usr/sbin/nginx        \
  • --conf-path=/etc/nginx/nginx.conf     \
  • --pid-path=/var/run/nginx.pid      \
  • --lock-path=/var/run/nginx.lock     \
  • --error-log-path=/var/log/nginx/error.log \
  • --http-log-path=/var/log/nginx/access.log \
  • --with-http_gzip_static_module        \
  • --with-http_stub_status_module     \
  • --with-http_ssl_module            \
  • --with-pcre                     \
  • --with-file-aio                 \
  • --with-http_realip_module         \
  • --without-http_scgi_module        \
  • --without-http_uwsgi_module       \
  • --without-http_fastcgi_module         \
  • --add-module=/home/ubuntu/softs/ngx_http_google_filter_module \
  • --add-module= /home/ubuntu/softs/ngx_http_substitutions_filter_module \

具体的编译参数可以通过nginx -V查到。

  • --add-module指定插件的保存位置。

接下来编译安装。

  • $ make
  • $ sudo make install

重启服务。

  • $ sudo make upgrade

还可以用nginx -V查看是否编译成功。

3. 配置使用

打开配置文件/etc/nginx/nginx.conf。

  • server {
  •   # ... part of server configuration
  •   resolver 8.8.8.8;
  •   location / {
  •     google on;
  •   }
  •   # ...
  • }

找到server部分,添加resolver和location两个指令,总共四行。

让配置文件生效。

  • $ sudo nginx -s reload

最后访问你站点网址,就会反向代理到 Google 站点。

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门