Nginx正向代理模块详解-http-proxy-connect
1、模块简介
- 官方REDEME:This module provides support for the CONNECT method request. This method is mainly used to tunnel SSL requests through proxy servers.
该模块为CONNECT方法请求提供支持。 此方法主要用于通过代理服务器转发SSL请求。
1.1、模块下载地址
- 目前支持版本支持如下(请前往如上地址实时查看):
nginx version | enable REWRITE phase | patch |
---|---|---|
1.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 | YES | proxy_connect_rewrite_101504.patch |
OpenResty version | enable REWRITE phase | patch |
---|---|---|
1.13.6 | NO | proxy_connect_1014.patch |
1.13.6 | YES | proxy_connect_rewrite_1014.patch |
1.15.8 | YES | proxy_connect_rewrite_101504.patch |
2、安装环境介绍
平台 | IP | NGINX版本 | 安装模块 | |
---|---|---|---|---|
CentOS 6.7 64Bit | 192.168.1.219 | NGINX-1.10.3 | ngx_http_proxy_connect_module |
3、模块安装
3.1、Build nginx
1 | [root@test0002 soft]# tar xzvf nginx-1.10.3.tar.gz |
3.2、Config nginx
1 | [root@test0002 vhost_conf]# vim proxy_9999.conf |
3.3、Error Log
- This module logs its own error message beginning with
"proxy_connect:"
string.
Some typical error logs are shown as following:The proxy_connect module tries to establish tunnel connection with backend server, but the TCP connection timeout occurs.
1 | 2019/08/07 17:27:20 [error] 19257#0: *1 proxy_connect: upstream connect timed out (peer:216.58.200.4:443) while connecting to upstream, client: 127.0.0.1, server: , request: "CONNECT www.google.com:443 HTTP/1.1", host: "www.google.com:443" |
3.4、Directive
1 | proxy_connect |
1 | proxy_connect_allow |
1 | proxy_connect_connect_timeout |
1 | proxy_connect_read_timeout |
1 | proxy_connect_send_timeout |
1 | proxy_connect_address |
3.5、Variables
1 | $connect_host |
1 | $connect_port |
1 | $connect_addr |
1 | $proxy_connect_connect_timeout |
1 | #For example: |
1 | $proxy_connect_read_timeout |
1 | $proxy_connect_send_timeout |
4、正向代理访问测试
4.1、Example for curl
- With above configuration, you can get any https website via HTTP CONNECT tunnel. A simple test with command curl is as following:
1 | [root@test0002 vhost_conf]# curl https://www.baidu.com/ -v -x 127.0.0.1:9999 |
4.2、Example for browser
- You can configure your browser to use this nginx as PROXY server.
4.3、linux客户端测试
1 | [root@test0002 ~]# vim /etc/profile |
1 | [root@test0002 ~]# curl -v https://www.baidu.com/ |