参考
ngxin正向代理需要打第三方的补丁: github.com/chobits/ngx_http_proxy_connect_module
nginx 使用的源码包版本为:nginx-1.9.12.tar.gz
注意:该补丁可能不兼容其他版本的nginx

1、获取nginx正向代理模块

  1. git clone https://github.com/chobits/ngx_http_proxy_connect_module

2、下载nginx源码包

  1. wget nginx.org/download/nginx-1.9.12.tar.gz
  2. tar xf nginx-1.9.12.tar.gz

3、打补丁

通过补丁方法把上述下载的正向代理模块导入到nginx模块存储目录

  1. # 进入nginx 主目录,否则patch 会失败
  2. cd nginx-1.9.12/
  3. patch -p1 < /root/ngx_http_proxy_connect_module/patch/proxy_connect.patch
  4. ##
  5. 输出:
  6. patching file src/http/ngx_http_core_module.c
  7. patching file src/http/ngx_http_parse.c
  8. patching file src/http/ngx_http_request.c
  9. patching file src/http/ngx_http_request.h
  10. patching file src/http/ngx_http_variables.c
  11. 表示成功

4、编译安装

  1. yum -y install openssl-devel zlib-devel prce-devel
  2. ./configure --add-module=/root/ngx_http_proxy_connect_module
  3. make && make install

5、修改配置文件

  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. '$status $body_bytes_sent "$http_referer" '
  15. '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. keepalive_timeout 65;
  20. #gzip on;
  21. # 正向代理
  22. server {
  23. listen 8083;
  24. resolver 8.8.8.8;
  25. proxy_connect;
  26. proxy_connect_allow 443 563;
  27. #charset koi8-r;
  28. #access_log logs/host.access.log main;
  29. location / {
  30. proxy_pass https://$host$request_uri; #设定https代理服务器的协议和地址
  31. proxy_set_header HOST $host;
  32. proxy_buffers 256 4k;
  33. proxy_max_temp_file_size 0k;
  34. proxy_connect_timeout 30;
  35. proxy_send_timeout 60;
  36. proxy_read_timeout 60;
  37. proxy_next_upstream error timeout invalid_header http_502;
  38. }
  39. }
  40. }

6、启动

  1. /usr/local/nginx/sbin/nginx -t #检查配置文件
  2. /usr/local/nginx/sbin/nginx # 启动服务
  3. /usr/local/nginx/sbin/nginx -s stop #关闭
  4. /usr/local/nginx/sbin/nginx -s reload #重启加载配置文件
  5. ss -anput | grep ":8083" #检查端口