nginx正向代理默认只支持http,不支持https,需借助第三方模块“ngx_http_proxy_connect_module”来实现(https://github.com/chobits/ngx_http_proxy_connect_module)
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
patch -p1 </newData/soft/ngx_http_proxy_connect_module-master/patch/proxy_connect_rewrite_1018.patch
./configure --prefix=/usr/local/nginx2 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-threads --add-module=/newData/soft/ngx_http_proxy_connect_module-master
make & make install
nginx配置同时支持http和https
server {
resolver 114.114.114.114 8.8.8.4 8.8.8.8; #多开几个,否则部分网站打不开
listen 109;
proxy_connect;
proxy_connect_allow all; #支持不同端口https
proxy_ignore_client_abort on;
location / {
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_ssl_server_name on;
proxy_pass $scheme://$http_host$request_uri;
proxy_set_header Host $http_host; #$http_host; #$host;
proxy_set_header Content-Type $content_type;
proxy_send_timeout 60000;
proxy_read_timeout 60000;
proxy_next_upstream error timeout invalid_header http_502;
}
}
如果碰到这种错误
make[1]: *** No rule to make target ‘objs/addon/ngx_http_mytest2/ngx_http_mytest2_module.o’, needed by ‘objs/nginx’. Stop.
1.确认上面安装的nginx模块是否都正确
2.ngx_http_proxy_connect_module-master 如果是从windows上拷过去,可能会有些文件不正确,需仔细确认