参考
ngxin正向代理需要打第三方的补丁: github.com/chobits/ngx_http_proxy_connect_module
nginx 使用的源码包版本为:nginx-1.9.12.tar.gz
注意:该补丁可能不兼容其他版本的nginx
1、获取nginx正向代理模块
git clone https://github.com/chobits/ngx_http_proxy_connect_module
2、下载nginx源码包
wget nginx.org/download/nginx-1.9.12.tar.gz
tar xf nginx-1.9.12.tar.gz
3、打补丁
通过补丁方法把上述下载的正向代理模块导入到nginx模块存储目录
# 进入nginx 主目录,否则patch 会失败
cd nginx-1.9.12/
patch -p1 < /root/ngx_http_proxy_connect_module/patch/proxy_connect.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
表示成功
4、编译安装
yum -y install openssl-devel zlib-devel prce-devel
./configure --add-module=/root/ngx_http_proxy_connect_module
make && make install
5、修改配置文件
#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 65;
#gzip on;
# 正向代理
server {
listen 8083;
resolver 8.8.8.8;
proxy_connect;
proxy_connect_allow 443 563;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass https://$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;
}
}
}
6、启动
/usr/local/nginx/sbin/nginx -t #检查配置文件
/usr/local/nginx/sbin/nginx # 启动服务
/usr/local/nginx/sbin/nginx -s stop #关闭
/usr/local/nginx/sbin/nginx -s reload #重启加载配置文件
ss -anput | grep ":8083" #检查端口