1. Install related software
#
# Install gcc & git
Apt-get install build-essential git gcc g ++ make
# Download the latest Nginx source code
# Http://nginx.org/en/download.html
Wget http://nginx.org/download/nginx-1.9.2.tar.gz"
# Download the latest version of pcre
# Http://www.pcre.org/
Wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz"
# Download the latest openssl version
# Https://www.openssl.org/
Wget https://www.openssl.org/source/openssl-1.0.2c.tar.gz"
# Download the latest zlib version
# Http://www.zlib.net/
Wget http://zlib.net/zlib-1.2.8.tar.gz"
# Download this extension
Git clone https://github.com/cuber/ngx_http_google_filter_module
# Download the substitutions extension
Git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module
# Decompress
Tar xzvf nginx-1.9.2.tar.gz
Tar xzvf pcre-8.36.tar.gz
Tar xzvf openssl-1.0.2c.tar.gz
Tar xzvf zlib-1.2.8.tar.gz
# Go to the nginx Source Code Directory
Cd nginx-1.9.2
# Set compilation options
./Configure \
-- Prefix =/opt/nginx-1.9.2 \
-- With-pcre = ../pcre-8.36 \
-- With-openssl = ../openssl-1.0.2c \
-- With-zlib = ../zlib-1.2.8 \
With-http_ssl_module \
-- Add-module = ../ngx_http_google_filter_module \
-- Add-module = ../ngx_http_substitutions_filter_module
Make
Sudo make install
# Start Nginx
Sudo/opt/nginx-1.9.2/sbin/nginx
2. Configure Nginx
Edit/opt/nginx-1.9.2/conf/nginx. conf
My configuration is as follows. The red part is the content modified/appended to the default configuration.
# User nobody;
Worker_processes 1;
# Error_log logs/error. log;
# Error_log logs/error. log notice;
# Error_log logs/error. log info;
# Pid logs/nginx. pid;
Events {
Worker_connections 1024;
}
Http {
Include mime. types;
Default_type application/octet-stream;
# Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request "'
# '$ Status $ body_bytes_sent "$ http_referer "'
# '"$ Http_user_agent" "$ http_x_forwarded_for "';
# Access_log logs/access. log main;
Sendfile on;
# Tcp_nopush on;
# Keepalive_timeout 0;
Keepalive_timeout 65;
# Gzip on;
Server {
# Force http redirect to https
Listen 80;
Server_name domain name;
Rewrite ^/(. *) https: // domain name/$1 permanent;
}
Server {
Listen 443;
Server_name domain name;
Ssl on;
Ssl_certificate certificate. crt path;
Ssl_certificate_key certificate. key path;
Resolver 8.8.8.8;
# Charset KOI8-R;
# Access_log logs/host. access. log main;
Location /{
# It is important to add academic support for Google and Google!
Google on;
Google_scholar on;
}
# Error_page 404/404 .html;
# Redirect server error pages to the static page/50x.html
#
Error_page 500 502 503 x.html;
Location =/50x.html {
Root html;
}
}
}
At last, reload the Nginx configuration to see the Google page.
/Opt/nginx-1.9.2/sbin/nginx-s reload