從事技術工作的朋友一般都會深諳至少一種打開谷歌搜索的方法,新手可以選擇修改hosts,善於折騰的也可以考慮自建科學上網等等。今天幫某位程序猿同學在廉價的美國主機上搭建一個簡易的谷歌搜索鏡像站,給大家分享一下搭建方法。說明一下,在國外垃圾主機上自建的谷歌鏡像站不建議公開分享,最好獨享或者只分享給極少部分的朋友使用。
某大佬的谷歌鏡像站:http://google.wanghualang.com (鏡像演示,隨時失效)
實驗環境:美國垃圾主機
操作系統:CentOS 6.9
Pcre:8.42
Zlib:1.2.11
Nginx:1.14.0
OpenSSL:1.0.2o
Ngx_http_google_filter_module
Ngx_http_substitutions_filter_module
第一步 准備工作
禁用SElinux
- [root@Wanghualang ~]# setenforce 0
- [root@Wanghualang ~]# sed -ri 's#^(SELINUX=).*#\1disabled#g' /etc/selinux/config
禁用防火牆
- [root@Wanghualang ~]# service iptables stop
- [root@Wanghualang ~]# service ip6tables stop
- [root@Wanghualang ~]# chkconfig iptables off
- [root@Wanghualang ~]# chkconfig ip6tables off
安裝常用軟件
- [root@Wanghualang ~]# yum -y install wget vim unzip
第二步 下載解壓源碼包
以下為相關軟件源碼包的官方下載頁面或作者發布頁面:
https://ftp.pcre.org/pub/pcre/
http://zlib.net/
http://nginx.org/en/download.html
https://www.openssl.org/source/
https://github.com/cuber/ngx_http_google_filter_module
https://github.com/yaoweibin/ngx_http_substitutions_filter_module
下載、解壓源碼包
- [root@Wanghualang ~]# cd /usr/local/src/
- [root@Wanghualang src]# wget --no-check-certificate https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
- [root@Wanghualang src]# wget --no-check-certificate http://zlib.net/zlib-1.2.11.tar.gz
- [root@Wanghualang src]# wget --no-check-certificate https://www.openssl.org/source/openssl-1.0.2o.tar.gz
- [root@Wanghualang src]# wget --no-check-certificate http://nginx.org/download/nginx-1.14.0.tar.gz
- [root@Wanghualang src]# wget --no-check-certificate -O ngx_http_google_filter_module.zip https://github.com/cuber/ngx_http_google_filter_module/archive/master.zip
- [root@Wanghualang src]# wget --no-check-certificate -O ngx_http_substitutions_filter_module.zip https://github.com/yaoweibin/ngx_http_substitutions_filter_module/archive/master.zip
- [root@Wanghualang src]# tar xzf pcre-8.42.tar.gz
- [root@Wanghualang src]# tar xzf zlib-1.2.11.tar.gz
- [root@Wanghualang src]# tar xzf openssl-1.0.2o.tar.gz
- [root@Wanghualang src]# tar xzf nginx-1.14.0.tar.gz
- [root@Wanghualang src]# unzip ngx_http_google_filter_module.zip
- [root@Wanghualang src]# unzip ngx_http_substitutions_filter_module.zip
第三步 安裝Nginx
精簡版的操作系統,在接下來的configure階段肯定會出現缺失相關開發包的報錯,根據提示安裝相關開發包即可。教程中為了做到一氣呵成,先提前安裝好需要的開發包。
- [root@Wanghualang ~]# yum -y install make gcc gcc-c++
編譯安裝軟件
- [root@Wanghualang ~]# cd /usr/local/src/nginx-1.14.0
- [root@Wanghualang nginx-1.14.0]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre=../pcre-8.42 --with-openssl=../openssl-1.0.2o --with-zlib=../zlib-1.2.11 --add-module=../ngx_http_google_filter_module-master --add-module=../ngx_http_substitutions_filter_module-master
- [root@Wanghualang nginx-1.14.0]# make
- [root@Wanghualang nginx-1.14.0]# make install
第四步 配置啟動Nginx
編輯Nginx主配置文件,
- [root@Wanghualang ~]# vim /usr/local/nginx/conf/nginx.conf
大約在第37行,找到server_name localhost,把localhost修改為VPS主機的IP地址,也可以修改為域名。接着在這一行下面插入內容:resolver 8.8.8.8;
最終修改如下:
- server_name google.wanghualang.com;
- resolver 8.8.8.8;
大約在第43行,找到location / {,在這一行往下插入內容:
- google on;
- google_scholar on;
最終修改如下:
- location / {
- google on;
- google_scholar on;
- root html;
- index index.html index.htm;
- }
啟動Nginx
- [root@Wanghualang ~]# /usr/local/nginx/sbin/nginx
也可以直接下載附件中已編譯好的Nginx,解壓后修改一下主配置文件中的ServerName,就可以啟動使用。
使用瀏覽器訪問:http://IP地址,若能看到谷歌搜索首頁,表示配置成功!