nginx代理机器 | 使用代理机器 |
---|---|
192.168.0.1 | 192.168.0.2 |
nginx下载地址:http://nginx.org/en/download.html
nginx https代理插件:https://github.com/chobits/ngx_http_proxy_connect_module
nginx和ngx_http_proxy_connect_module需要版本对应
nginx版本 | ngx_http_proxy_connect_module版本 | |
---|---|---|
.4.x ~ 1.12.x | NO | proxy_connect.patch |
1.4.x ~ 1.12.x | YES | proxy_connect_rewrite.patch |
1.13.x ~ 1.14.x | NO | proxy_connect_1014.patch |
1.13.x ~ 1.14.x | YES | proxy_connect_rewrite_1014.patch |
1.15.2 | YES | proxy_connect_rewrite_1015.patch |
1.15.4 ~ 1.16.x | YES | proxy_connect_rewrite_101504.patch |
1.17.x ~ 1.18.0 | YES | proxy_connect_rewrite_1018.patch |
1.19.x ~ 1.21.0 | YES | proxy_connect_rewrite_1018.patch |
1.21.1 ~ 1.22.1 | YES | proxy_connect_rewrite_102101.patch |
1.23.x | YES | proxy_connect_rewrite_102101.patch |
现在大部分网站都是基于https实现的,所以我们的代理还需要实现htpps的转发,nginx基本的功能是没有https的
机器:192.168.0.1
yum -y install gcc gcc-c++ pcre-devel pcre zlib-devel zlib openssl-devel openssl patch
nginx-1.22.1.tar.gz 和 ngx_http_proxy_connect_module下载位置:/home/nginx
ngx_http_proxy_connect_module下载后名称是:master.zip
cd /home/nginx
unzip master.zip
tar -zxvf nginx-1.22.1.tar.gz
进入到nginx解压目录。执行以下命令,如下所示便是成功了
[root@localhost nginx]# cd nginx-1.22.1/.
[root@localhost nginx-1.22.1]# patch -p1 < /home/nginx/ngx_http_proxy_connect_module-master/patch/proxy_connect_rewrite_102101.patch
patching file src/http/ngx_http_core_module.c
patching file src/http/ngx_http_parse.c
patching file src/http/ngx_http_request.c
patching file src/http/ngx_http_request.h
patching file src/http/ngx_http_variables.c
开始编译安装nginx
./configure --prefix=/usr/local/nginx --http-client-body-temp-path=/usr/local/nginx/client_temp --http-proxy-temp-path=/usr/local/nginx/proxy_temp --http-fastcgi-temp-path=/usr/local/nginx/fastcgi_temp --http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-file-aio --with-http_degradation_module --with-http_slice_module --with-stream --with-stream_ssl_module --with-http_sub_module --with-pcre --add-dynamic-module=/home/nginx/ngx_http_proxy_connect_module-master --add-module=/home/nginx/ngx_http_proxy_connect_module-master
make
make install
安装完成
[root@localhost nginx]# cd /usr/local/nginx/conf
[root@localhost conf.d]# vim nginx.conf
添加以下代码
server {listen 8080;resolver 114.114.114.114;proxy_connect;proxy_connect_allow 443 563 1000-50000;proxy_connect_connect_timeout 10s;proxy_connect_data_timeout 10s;location / {proxy_ssl_server_name on;proxy_set_header Host $host;proxy_set_header X-Real-Ip $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header Remote_Addr $remote_addr;proxy_http_version 1.1;proxy_buffers 256 4k;proxy_max_temp_file_size 0k;proxy_connect_timeout 30;proxy_send_timeout 60;proxy_read_timeout 60;proxy_next_upstream error timeout invalid_header http_502;proxy_pass $scheme://$host$request_uri;}
}
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
机器:192.168.0.2
vim /etc/profile
source /etc/profile
PROXY_URL="http://192.168.0.1:8080/"
NO_PROXY_ADDR="127.0.0.1,localhost,.local,.cluster.local"
export http_proxy="$PROXY_URL"
export https_proxy="$PROXY_URL"
export no_proxy="$NO_PROXY_ADDR"
export HTTP_PROXY="$PROXY_URL"
export HTTPS_PROXY="$PROXY_URL"
export NO_PROXY="$NO_PROXY_ADDR"
上一篇:安徒生童话读后感大全
下一篇:顺口的烧烤店名字有哪些?