Nginx reverse proxy building tutorial

Foreword

Because of the need to be a Google academic reverse proxy, it happens that nginx has a corresponding module, but the version does not support the latest version of nginx, so I chose the old version of nginx 1.78 and the system version centos7.

Install Nginx

Install dependencies

yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel  git make

Download nginx

wget "http://nginx.org/download/nginx-1.7.8.tar.gz"

Download google extension

git clone https://github.com/cuber/ngx_http_google_filter_module

Download substitutions extension

git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module

Unzip & enter the source code directory

tar xzvf nginx- 1.7 . 8 . tar .gz 
cd nginx - 1.7 . 8

Compile and install

./configure \
  --prefix=/etc/nginx \--with-http_ssl_module \
--with-http_stub_status_module \
--add-module=/root/ngx_http_google_filter_module \ --add-module=/root/ngx_http_substitutions_filter_module

Configure environment variables

vim / etc / profile // Edit the file 
 
export PATH = $ PATH: / usr / sbin / nginx / sbin // add this line 

source ~ / .bashrc // take effect

 nginx management

nginx // Start 
nginx - s stop // Stop 
nginx -s reload // Restart

 

Modify nginx configuration file

server {

    listen 443 ssl;
    server_name 域名;
    ssl_certificate /etc/nginx/ssl/xx.pro_chain.crt;
    ssl_certificate_key /etc/nginx/ssl/xx.pro_key.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    resolver 8.8.8.8;
    
    location / {
        subs_filter_types *;
        google on;
        google_scholar on;
    }
}

This module combines academic and search, and implements URL rewriting through two domain names to bind academic to independent domain names

    server {
        listen 443 ssl;
        server_name xx.pro;  #域名
        ssl_certificate /etc/nginx/ssl/xx.pro_chain.crt;
        ssl_certificate_key /etc/nginx/ssl/xx.pro_key.key; 
        
        location / {

        if ($request_uri ~* "/scholar\?"){
            proxy_pass https://www.xx.pro/scholar?$args;
            break;
        }
            proxy_pass https://www.xx.pro/scholar/;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

 

Guess you like

Origin www.cnblogs.com/hlikex/p/12729246.html