nginx 正向代理

这里使用 openresty

安装基础包

yum install -y gcc make autoconf patch
yum install -y pcre-devel openssl-devel

下载 openresty 源码包和 ngx_http_proxy_connect_module 模块, 编译安装

wget https://openresty.org/download/openresty-1.21.4.3.tar.gz
git clone https://github.com/chobits/ngx_http_proxy_connect_module.git /tmp/ngx_http_proxy_connect_module

tar xf openresty-1.21.4.3.tar.gz -C /tmp/
cd /tmp/openresty-1.21.4.3

./configure -j2 \
    --with-stream \
    --with-pcre-jit \
    --with-http_stub_status_module \
    --with-http_ssl_module \
    --with-http_v2_module \
    --add-module=/tmp/ngx_http_proxy_connect_module

patch -d build/nginx-1.21.4/ -p 1 < /tmp/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_102101.patch

gmake && gmake install

配置正向代理

# nginx.conf
    server {
        listen     3128;

        resolver   8.8.8.8;

        proxy_connect;
        proxy_connect_allow            443 563;
        proxy_connect_connect_timeout  60s;
        proxy_connect_data_timeout     60s;

        location / {
            proxy_pass http://$host;
            proxy_set_header Host $host;
        }
    }

# start openresty
/usr/local/openresty/bin/openresty -t && /usr/local/openresty/bin/openresty

# 测试
curl --proxy 172.18.21.139:3128 https://www.resumesdk.com
posted @ 2024-11-21 09:39  运维工作栈  阅读(37)  评论(0)    收藏  举报