/ngx_http_google_filter_module

Nginx Module for Google Mirror

Primary LanguageCGNU General Public License v2.0GPL-2.0

Nginx Module for Google

Description

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.
Let's see how easy it is to setup a google mirror.

location / {
  google on;
}

What? Are you kidding me?
Yes, it's just that simple!

Demo site https://wen.lu

Demo Site

Dependency

  1. pcre regular expression support
  2. ngx_http_proxy_module backend proxy support
  3. ngx_http_substitutions_filter_module mutiple substitutions support

Installation

Download sources first
#
# download the newest source
# @see http://nginx.org/en/download.html
#
wget http://nginx.org/download/nginx-1.7.8.tar.gz

#
# clone ngx_http_google_filter_module
# @see https://github.com/cuber/ngx_http_google_filter_module
#
git clone https://github.com/cuber/ngx_http_google_filter_module

#
# clone ngx_http_substitutions_filter_module
# @see https://github.com/yaoweibin/ngx_http_substitutions_filter_module
#
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module
Brand new installation
#
# configure nginx customly
# replace </path/to/> to your real path
#
./configure \
  <your configuration> \
  --add-module=</path/to/>ngx_http_google_filter_module \
  --add-module=</path/to/>ngx_http_substitutions_filter_module
Migrate from existed distribution
#
# get the configuration of existed nginx
# replace </path/to/> to your real path
#
</path/to/>nginx -V
> nginx version: nginx/ <version>
> built by gcc 4.x.x
> configure arguments: <configuration>

#
# download the same version of nginx source
# @see http://nginx.org/en/download.html
# replace <version> to your nginx version
#
wget http://nginx.org/download/nginx-<version>.tar.gz
  
#
# configure nginx
# replace <configuration> to your nginx configuration
# replace </path/to/> to your real path
#
./configure \
  <configuration> \
  --add-module=</path/to/>ngx_http_google_filter_module \
  --add-module=</path/to/>ngx_http_substitutions_filter_module
#
# if some libraries were missing, you should install them with the package manager
#   eg. apt-get, pacman, yum ...
#

Usage

Basic Configuration

resolver is needed to resolve domains.

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

google_scholar depends on google, so google_scholar cannot be used independently.
Because the tld of google scholar is not the same in different region, so the domain of google scholar should be specific.
Get the tld of google scholar.

curl "scholar.google.com" -I
HTTP/1.1 302 Found
Location: http://scholar.google.co.jp/

Configuration nginx.

location / {
  google on;
  google_scholar "scholar.google.co.jp";
}
Upstreaming

upstream can help you avoid name resolving cost, and decrease the possibility of google robot detection.

upstream www.google.com {
  server 173.194.38.1:443;
  server 173.194.38.2:443;
  server 173.194.38.3:443;
  server 173.194.38.4:443;
}

Copyright & License

All codes are under GPLv2
Copyright (C) 2014 by Cube.