用于处理 CONNECT 请求的前向代理模块
``` … ```
Example for browser ------------------- You can configure your browser to use this nginx as PROXY server. * Google Chrome HTTPS PROXY SETTING: [guide & config](https://github.com/chobits/ngx_http_proxy_connect_module/issues/22#issuecomment-346941271) for how to configure this module working under SSL layer. Example for Basic Authentication -------------------------------- We can do access control on CONNECT request using nginx auth basic module. See [this guide](https://github.com/chobits/ngx_http_proxy_connect_module/issues/42#issuecomment-502985437) for more details. Example for proxying WebSocket ------------------------------ * Note that nginx has its own WebSocket reverse proxy module, which is is not limited to the CONNECT tunnel, see [nginx.org doc: Nginx WebSocket proxying](https://nginx.org/en/docs/http/websocket.html) and [nginx.com blog: NGINX as a WebSocket Proxy](https://www.nginx.com/blog/websocket-nginx/). * This module enables the WebSocket protocol to work over the CONNECT tunnel, see https://github.com/chobits/ngx_http_proxy_connect_module/issues/267#issuecomment-1575449174 Install ======= Select patch ------------ * Select right patch for building: * All patch files have been included in `patch/` directory of this module. You dont need to download the patch directly from web page. | nginx version | enable REWRITE phase | patch | | --: | --: | --: | | 1.4.x ~ 1.12.x | NO | [proxy_connect.patch](patch/proxy_connect.patch) | | 1.4.x ~ 1.12.x | YES | [proxy_connect_rewrite.patch](patch/proxy_connect_rewrite.patch) | | 1.13.x ~ 1.14.x | NO | [proxy_connect_1014.patch](patch/proxy_connect_1014.patch) | | 1.13.x ~ 1.14.x | YES | [proxy_connect_rewrite_1014.patch](patch/proxy_connect_rewrite_1014.patch) | | 1.15.2 | YES | [proxy_connect_rewrite_1015.patch](patch/proxy_connect_rewrite_1015.patch) | | 1.15.4 ~ 1.16.x | YES | [proxy_connect_rewrite_101504.patch](patch/proxy_connect_rewrite_101504.patch) | | 1.17.x ~ 1.18.x | YES | [proxy_connect_rewrite_1018.patch](patch/proxy_connect_rewrite_1018.patch) | | 1.19.x ~ 1.21.0 | YES | [proxy_connect_rewrite_1018.patch](patch/proxy_connect_rewrite_1018.patch) | | 1.21.1 ~ 1.22.x | YES | [proxy_connect_rewrite_102101.patch](patch/proxy_connect_rewrite_102101.patch) | | 1.23.x ~ 1.24.0 | YES | [proxy_connect_rewrite_102101.patch](patch/proxy_connect_rewrite_102101.patch) | | 1.25.0 ~ 1.26.x | YES | [proxy_connect_rewrite_102101.patch](patch/proxy_connect_rewrite_102101.patch) | | 1.27.1 | YES | [proxy_connect_rewrite_102101.patch](patch/proxy_connect_rewrite_102101.patch) | | OpenResty version | enable REWRITE phase | patch | | --: | --: | --: | | 1.13.6 | NO | [proxy_connect_1014.patch](patch/proxy_connect_1014.patch) | | 1.13.6 | YES | [proxy_connect_rewrite_1014.patch](patch/proxy_connect_rewrite_1014.patch) | | 1.15.8 | YES | [proxy_connect_rewrite_101504.patch](patch/proxy_connect_rewrite_101504.patch) | | 1.17.8 | YES | [proxy_connect_rewrite_1018.patch](patch/proxy_connect_rewrite_1018.patch) | | 1.19.3 | YES | [proxy_connect_rewrite_1018.patch](patch/proxy_connect_rewrite_1018.patch) | | 1.21.4 | YES | [proxy_connect_rewrite_102101.patch](patch/proxy_connect_rewrite_102101.patch) | | 1.25.3 | YES | [proxy_connect_rewrite_102101.patch](patch/proxy_connect_rewrite_102101.patch) | * `proxy_connect_.patch` disables nginx REWRITE phase for CONNECT request by default, which means `if`, `set`, `rewrite_by_lua` and other REWRITE phase directives cannot be used. * `proxy_connect_rewrite_.patch` enables these REWRITE phase directives. Build nginx ----------- * Build nginx with this module from source: ```bash $ wget http://nginx.org/download/nginx-1.9.2.tar.gz $ tar -xzvf nginx-1.9.2.tar.gz $ cd nginx-1.9.2/ $ patch -p1 < /path/to/ngx_http_proxy_connect_module/patch/proxy_connect.patch $ ./configure --add-module=/path/to/ngx_http_proxy_connect_module $ make && make install ``` Build as a dynamic module ------------------------- * Starting from nginx 1.9.11, you can also compile this module as a dynamic module, by using the `--add-dynamic-module=PATH` option instead of `--add-module=PATH` on the `./configure` command line. ```bash $ wget http://nginx.org/download/nginx-1.9.12.tar.gz $ 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 ``` * And then you can explicitly load the module in your nginx.conf via the `load_module` directive, for example, ``` load_module /path/to/modules/ngx_http_proxy_connect_module.so; ``` * :exclamation: Note that the ngx_http_proxy_connect_module.so file MUST be loaded by nginx binary that is compiled with the .so file at the same time. Build OpenResty --------------- * Build OpenResty with this module from source: ```bash $ wget https://openresty.org/download/openresty-1.19.3.1.tar.gz $ tar -zxvf openresty-1.19.3.1.tar.gz $ cd openresty-1.19.3.1 $ ./configure --add-module=/path/to/ngx_http_proxy_connect_module $ patch -d build/nginx-1.19.3/ -p 1 < /path/to/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_101504.patch $ make && make install ``` Test Suite ========== * To run the whole test suite: ```bash $ hg clone http://hg.nginx.org/nginx-tests/ # If you use latest lua-nginx-module that needs lua-resty-core and # lua-resty-lrucache, you should add "lua_package_path ...;" directive # into nginx.conf of test cases. You can use the following command: # # $ export TEST_NGINX_GLOBALS_HTTP='lua_package_path "/path/to/nginx/lib/lua/?.lua;;";' $ export TEST_NGINX_BINARY=/path/to/nginx/binary $ prove -v -I /path/to/nginx-tests/lib /path/to/ngx_http_proxy_connect_module/t/ ``` * For the complete process of building and testing this module, see: * workflow files: [here](https://github.com/chobits/ngx_http_proxy_connect_module/tree/master/.github/workflows) * runs from all workflows: [here](https://github.com/chobits/ngx_http_proxy_connect_module/actions) 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. ``` 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" ``` Directive ========= proxy_connect ------------- Syntax: **proxy_connect*暂无开放 Issues,或尚未同步最近议题。