Centos7 手动编译nginx,搭建正向代理

Centos7 手动编译nginx,搭建正向代理

下载nginx1.16.1

wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar xf nginx-1.16.1.tar.gz
cd nginx-1.16.1

下载ngx_http_proxy_connect_module,echo-nginx-module

git clone https://github.com/chobits/ngx_http_proxy_connect_module
git clone https://github.com/openresty/echo-nginx-module

打补丁

patch -p1 < ./ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_101504.patch

configure

./configure --prefix=/opt/nginx --add-module=./ngx_http_proxy_connect_module --add-module=./echo-nginx-module --prefix=/usr/local/nginx --with-stream

make&install

make;make install
ln -sf /usr/local/nginx/sbin/nginx /sbin/nginx

配置nginx.conf

   server {
       listen                         3128;
       # dns resolver used by forward proxying
       resolver                       114.114.114.114;

       # forward proxy for CONNECT request
       proxy_connect;
       proxy_connect_allow            443 563;
       proxy_connect_connect_timeout  10s;
       proxy_connect_read_timeout     10s;
       proxy_connect_send_timeout     10s;

       # forward proxy for non-CONNECT request
       location / {
           proxy_pass http://$host;
           proxy_set_header Host $host;
       }
   }

启动

nginx -t;nginx

验证

curl  baidu.com -v -x 127.0.0.1:3128
posted @ 2021-06-24 22:08  doite  阅读(157)  评论(0)    收藏  举报