首先要感謝wen.lu的開源。參見GitHub地址:
https://github.com/cuber/ngx_http_google_filter_module
中文的說明文檔:
https://github.com/cuber/ngx_http_google_filter_module/blob/master/README.zh-CN.md
有GitHub的可以fork一份到自己的主頁。具體內容我就不復制過來了。
感謝V2EX。http://www.v2ex.com/t/154344
其次要準備一臺VPS,要在墻外(美國、日本、香港等,推薦Bandwagonhost,搬瓦工VPS中文網:www.bandwagonhost.cn)。最好是裝上Ubuntu14.04系統,因為目前網上流傳的教程都是基于這個系統。下面開始教程。
教程來自獸獸的通天塔,原文鏈接:
http://ttt.tt/162/
為防編輯,我復制如下:
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install libpcre3 libpcre3-dev zlib1g-dev libssl-dev build-essential git
mkdir nginx && cd nginx
下載 Nginx 最新穩定版,目前的版本是 1.6.2
,用 Git 克隆兩個 Nginx 模塊,一個是 wen.lu 開源的 ngx_http_google_filter_module,另一個是 Nginx 替換關鍵詞模塊 ngx_http_substitutions_filter_module
wget http://nginx.org/download/nginx-1.6.2.tar.gztar -xvf nginx-1.6.2.tar.gzgit clone https://github.com/cuber/ngx_http_google_filter_modulegit clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module
cd nginx-1.6.2mkdir /var/tmp/nginx
./configure /--prefix=/usr --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --http-scgi-temp-path=/var/tmp/nginx/scgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --with-http_ssl_module --with-http_gzip_static_module /--add-module=/root/nginx/ngx_http_google_filter_module /--add-module=/root/nginx/ngx_http_substitutions_filter_module
PS:如果需要支持 IPv6 請別忘記增加 IPv6 模塊 --with-ipv6
make && make install
默認這么安裝好以后每次檢查配置、重啟之類的操作略麻煩,所以我們模仿 Ubuntu 14.04 官方源,給系統設置個 nginx 服務,方便我們檢查配置、啟動重啟關閉 Nginx 以及開機自動啟動 Nginx
cd /etc/init.d/
vi nginx
#!/bin/sh### BEGIN INIT INFO# Provides: nginx# Required-Start: $local_fs $remote_fs $network $syslog# Required-Stop: $local_fs $remote_fs $network $syslog# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: starts the nginx web server# Description: starts nginx using start-stop-daemon### END INIT INFOPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binDAEMON=/usr/sbin/nginxNAME=nginxDESC=nginx# Include nginx defaults if availableif [ -f /etc/default/nginx ]; then . /etc/default/nginxfitest -x $DAEMON || exit 0set -e. /lib/lsb/init-functionstest_nginx_config() { if $DAEMON -t $DAEMON_OPTS >/dev/null 2>&1; then return 0 else $DAEMON -t $DAEMON_OPTS return $? fi}case "$1" in start) echo -n "Starting $DESC: " test_nginx_config # Check if the ULIMIT is set in /etc/default/nginx if [ -n "$ULIMIT" ]; then # Set the ulimits ulimit $ULIMIT fi start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid / --exec $DAEMON -- $DAEMON_OPTS || true echo "$NAME." ;; stop) echo -n "Stopping $DESC: " start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid / --exec $DAEMON || true echo "$NAME." ;; restart|force-reload) echo -n "Restarting $DESC: " start-stop-daemon --stop --quiet --pidfile / /var/run/$NAME.pid --exec $DAEMON || true sleep 1 test_nginx_config # Check if the ULIMIT is set in /etc/default/nginx if [ -n "$ULIMIT" ]; then # Set the ulimits ulimit $ULIMIT fi start-stop-daemon --start --quiet --pidfile / /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true echo "$NAME." ;; reload) echo -n "Reloading $DESC configuration: " test_nginx_config start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid / --exec $DAEMON || true echo "$NAME." ;; configtest|testconfig) echo -n "Testing $DESC configuration: " if test_nginx_config; then echo "$NAME." else exit $? fi ;; status) status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx && exit 0 || exit $? ;; *) echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2 exit 1 ;;esacexit 0
sudo chmod +x ./nginxsudo update-rc.d nginx defaults
默認官方的配置文件寫的很簡單,這里我們也模仿 Ubuntu 14.04 官方源修改一個適合我們的 Nginx 配置
/etc/nginx/nginx.conf
vi /etc/nginx/nginx.conf
具體內容如下:
worker_processes 4;pid /var/run/nginx.pid;events { worker_connections 768;}http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; server_tokens off; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; proxy_temp_file_write_size 128k; proxy_temp_path /var/cache/nginx/temp; proxy_cache_path /var/cache/nginx/cache levels=1:2 keys_zone=cache_one:100m inactive=7d max_size=10g; gzip_static on; gzip on; gzip_disable "msie6"; include /etc/nginx/sites-enabled/*;}
其中 /etc/nginx/sites-enabled
用來放我們的網站配置文件,/var/log/nginx
用來放 log 日志文件,/var/cache/nginx/cache
和/var/cache/nginx/temp
則是 Nginx 反代緩存文件夾。
mkdir -p /etc/nginx/sites-enabledmkdir -p /var/log/nginxmkdir -p /var/cache/nginx/cachemkdir -p /var/cache/nginx/temp
直接運行 nginx -t
如果輸出如下提示,則一切正常
nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
mkdir -p /root/ssl && cd /root/ssl
example.com.key
和 example.com.csr
openssl req -new -newkey rsa:2048 -nodes -out example.com.csr -keyout example.com.key -subj "/C=US/ST=CA/L=Los Angeles/O=Example Inc./OU=Web Security/CN=example.com"
如果是泛域名證書,最后的域名改成 *.example.com
驗證好域名以后會頒發給你一個 .crt
文件,我們命名為 example.com.crt
請自行更換配置文件里的域名和證書文件名
vi /etc/nginx/sites-enabled/google.conf
具體配置如下
server { listen 80; server_name example.com; return 301 https://example.com$request_uri;}server { listen 443 ssl; server_name example; ssl on; ssl_certificate /root/ssl/example.com.crt; ssl_certificate_key /root/ssl/example.com.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM; keepalive_timeout 70; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; resolver 8.8.8.8; location / { google on; google_scholar "scholar.google.com"; }}
service nginx restart
OK,大功告成!瀏覽器里訪問 https://example.com/
看看是否已經可以反代 Google 了。
1、Google 學術的域名各個地區的機房不一樣,請先運行 curl -I scholar.google.com
看看是否跳轉到了不同的域名,比如香港的服務器就會跳轉到 scholar.google.com.hk
,日本的就會跳轉到 scholar.google.co.jp
,那么相應的 google_scholar "scholar.google.com";
這行就要修改成你服務器里訪問到的域名
2、用的人過多以后 IP 會被 Google 限制,搜索的時候會要求輸入驗證碼,這里我們的解決方案是通過 DNS 輪轉到不同的服務器,這樣就會有不同的出口 IP,當然自己用的話沒啥問題。
摘錄一下獸獸另一個博客上關于nginx下安裝SSL的步驟,僅作參考。原文:
http://zou.lu/nginx-https-ssl-module/
1、Nginx 配置 ssl 模塊
默認 Nginx 是沒有 ssl 模塊的,而我的 VPS 默認裝的是 Nginx 0.7.63 ,順帶把 Nginx 升級到 0.7.64 并且 配置 ssl 模塊方法如下:
下載 Nginx 0.7.64 版本,解壓 進入解壓目錄:
wget http://sysoev.ru/nginx/nginx-0.7.64.tar.gz tar zxvf nginx-0.7.64.tar.gz cd nginx-0.7.64
如果要更改header信息的話,
vi src/core/nginx.h #define NGINX_VERSION "0.7.62" #define NGINX_VER "nginx/" NGINX_VERSION
上面的版本號和nginx自己修改
編譯
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module make && make install
如果有 IPV6 模塊,加上 主站蜘蛛池模板: 久久一级 | 欧美女同hd | 久久国产成人精品国产成人亚洲 | 一级电影免费在线观看 | 免费99热在线观看 | 久久99精品久久久久久国产越南 | 国产精品成年片在线观看, 激情小说另类 | 日本高清黄色片 | 一区二区三区日本在线观看 | 狠狠干伊人网 | 免费a级观看 | 在线亚洲欧美日韩 | 青青草最新网址 | 欧美a视频 | 日日草天天干 | 香蕉秀| 永久av在线免费观看 | 国产成人精品无人区一区 | 日韩精品免费一区二区三区 | 亚洲日色 | 黄色美女免费 | tube69xxxxxhd| 免费一级毛片在线播放视频 | 一级免费大片 | 国产一区二区精品91 | 护士xxxx | 一级电影在线免费观看 | 久久草在线视频国产 | 国产成人午夜高潮毛片 | 九一免费版在线观看 | 在线香蕉视频 | 27xxoo无遮挡动态视频 | 成人免费看毛片 | 精品一区二区三区免费毛片 | 久久99精品久久久久久236 | 天天夜天天操 | 草久在线 | 成人区一区二区 | 欧美精品一区二区中文字幕 | 特级西西444www大精品视频免费看 | 国产黄色录像片 |