nginx 配置http和https代理

https代理关键字connect

依赖ngx_http_proxy_connect_module 阿里封装的这个模块

https://github.com/chobits/ngx_http_proxy_connect_module#select-patch 下载对应版本

安装ngx_http_proxy_connect_module

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

2、https://github.com/chobits/ngx_http_proxy_connect_module#select-patch 下载对应版本

3、cd nginx目录,patch -p1 < patch文件路径

4、

./configure --add-module=/path/to/ngx_http_proxy_connect_module
make && make install

 

 

完整可运行例子

wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -xvf nginx-1.18.0.tar.gz
cd nginx-1.18.0/
patch -p1 < /home/qatools/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1018.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

./configure  --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-threads --add-module=/home/qatools/ngx_http_proxy_connect_module

make 
make install

 

 https://blog.csdn.net/yunqiinsight/article/details/93467393

简单的http代理,配置文件
 
server {
    resolver 114.114.114.114;
    listen 9999;
    access_log /var/log/nginx/http_proxy.access.log main;
    error_log /var/log/nginx/http_proxy.error.log;
 
    location / {
        proxy_pass $scheme://$http_host$request_uri;
    }
}
https/http代理配置文件
 
server {
    resolver 114.114.114.114;
    listen 9999;
 
    proxy_connect;
    proxy_connect_allow            443 563;
    proxy_connect_connect_timeout  10s;
    proxy_connect_read_timeout     10s;
    proxy_connect_send_timeout     10s;
 
    access_log /var/log/nginx/http_proxy.access.log main;
    error_log /var/log/nginx/http_proxy.error.log;
 
    location / {
        proxy_pass $scheme://$http_host$request_uri;
    }
}

  

posted @ 2021-08-25 14:19  zipon  阅读(1260)  评论(0编辑  收藏  举报