世界上最伟大的投资就是投资自己的教育

全场限时 5 折

首页Nginx
随风 · 练气

用 nginx 搭建谷歌镜像网站

随风发布于3285 次阅读

1. 介绍

搭建类似http://tokillgoogle.com/这样的网站,只是能让我们访问 google.com。用的工具是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 部分,添加resolverlocation两个指令,总共四行。

让配置文件生效。

$ sudo nginx -s reload

成功,看到效果。

本站文章均为原创内容,如需转载请注明出处,谢谢。

0 条回复
暂无回复~~
相关小书
nginx教程

nginx教程

最全面,最深入的nginx入门到精通的教程

发表于

喜欢
统计信息
    学员: 29204
    视频数量: 1985
    文章数量: 489

© 汕尾市求知科技有限公司 | Rails365 Gitlab | Qiuzhi99 Gitlab | 知乎 | b 站 | 搜索

粤公网安备 44152102000088号粤公网安备 44152102000088号 | 粤ICP备19038915号

Top