1

使用正向代理的场景,以及正向代理和反向代理的区别:

理解:
客户端 代理 服务器
A B C
正向: * B C
反向: A B *

正向隐藏客户端
反向隐藏服务端

1 查看文档

 https://github.com/chobits/ngx_http_proxy_connect_module/blob/master/README.md

2 其中: 构建为动态模块

安装nginx 和 nginx_proxy_connect module

从nginx的1.9.11开始,你也可以作为一个动态模块,通过使用编译该模块--add-dynamic-module=PATH选项,而不是--add-module=PATH在对./configure命令行。
$ $ wget http://nginx.org/download/ngi...
$ tar -xzvf nginx-1.9.12.tar.gz
$ cd nginx-1.9.12/
$ patch -p1 < /path/to/ngx_http_proxy_connect_module/patch/proxy_connect.patch
$ ./configure --add-dynamic-module=/path/to/ngx_http_proxy_connect_module
$ make && make install

3 make可能遇到的问题

1 error: this statement may fall through [-Werror=implicit-fallthrough=]
2 “src/os/unix/ngx_user.c:26:7: error: ‘struct crypt_data’ has no member named ‘current_salt’”

问题1解决,注释掉这一行

vim /opt/nginx/nginx-1.9.2/src/os/unix/ngx_user.c
36 : / cd.current_salt[0] = ~salt[0];/

问题2解决,编译加上参数 :
make CFLAGS='-Wno-implicit-fallthrough';
make install;

4 完成后 配置 conf :

vim /usr/local/nginx/conf/nginx.conf

#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;
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
 
server {
        listen 88;                #监听端口
        resolver 183.60.82.98;   #dns解析地址
        server_name  _;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
             proxy_pass https://$host$request_uri;     #设定http代理服务器的协议和地址
             proxy_set_header HOST $host;
             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;
            #root   html;
            #index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 
    }
 
 
 
server {
       resolver 8.8.8.8;   #dns解析地址
       listen 89;          #代理监听端口
       proxy_connect;
       proxy_connect_allow            443 563;
       location / {
             proxy_pass $scheme://$host$request_uri;     #设定https代理服务器的协议和地址
             proxy_set_header HOST $host;
             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;
 
       }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 
    }  
 
} 

启动 nginx

curl -i --proxy 192.168.3.17:89 www.baidu.com

结果 :

结果


韩琦
270 声望49 粉丝