Debian 系 OS 下源代码编译 nginx 并启用 ngx_http_proxy_connect_module

Posted by

on

前言

手握多个 Proxy Server,需要开启 HTTP Proxy。发现 nginx 并不支持 CONNECT 正向代理的语义,需要 ngx_http_proxy_connect_module 扩张 nginx 的机能。

因为总是需要手敲命令,故整理操作手册。

CLI

apt install gcc make openssl libssl-dev libpcre3 libpcre3-dev libgd-dev git
wget http://nginx.org/download/nginx-1.25.1.tar.gz
tar zxvf nginx-1.25.1.tar.gz
git clone https://github.com/chobits/ngx_http_proxy_connect_module.git
cd nginx-1.25.1
patch -p1 < ../ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_102101.patch
./configure --with-pcre --with-http_stub_status_module --with-http_v2_module --with-http_v3_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-pcre-jit --add-module=../ngx_http_proxy_connect_module
make && make install
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[Unit]
Description=NGINX - High Performance Web Server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPost=/bin/sleep 0.1
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> /usr/lib/systemd/system/nginx.service

systemctl daemon-reload
systemctl enable nginx
systemctl start nginx

参考

  1. GitHub: chobits/ngx_http_proxy_connect_module, https://github.com/chobits/ngx_http_proxy_connect_module
  2. nginx: download, https://nginx.org/en/download.html

Leave a Reply

Your email address will not be published. Required fields are marked *