运行以下脚本安装nginx , 该脚本只针对nginx-1.20.1 版本
#!/bin/bash
## install nginx
WORK_DIR=`mktemp -d`
yum install wget gcc gcc-c++ automake pcre pcre-devel zlib-devel openssl openssl-devel git libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed -y
cd $WORK_DIR
git clone https://github.com/chobits/ngx_http_proxy_connect_module.git
wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar zxvf nginx-1.20.1.tar.gz && cd nginx-1.20.1
patch -p1 < $WORK_DIR/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1018.patch
./configure --prefix=/opt/nginx --add-module=$WORK_DIR/ngx_http_proxy_connect_module --user=apache --group=apache --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-http_v2_module --with-http_dav_module --with-http_flv_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_sub_module --with-http_random_index_module --with-http_degradation_module --with-http_secure_link_module --with-http_perl_module --with-debug --with-file-aio --with-stream --with-ld-opt=-Wl,-E
make && make install
cd ~
[ -d $WORK_DIR ] && rm $WORK_DIR -rf
## 添加nginx运行账户
groupadd apache
useradd -g apache -s /sbin/nologin -c "apache" apache
下面是一个正向代理的配置文件示例:
server {
listen 0.0.0.0:10713;
access_log logs/10713.access.log;
error_log logs/10713.error.log;
resolver 114.114.114.114 ipv6=off; # 关闭ipv6 解决可能会出现失败的问题
proxy_connect;
proxy_connect_allow all; # 允许所有接口通过该端口转发
proxy_connect_connect_timeout 100s;
proxy_connect_read_timeout 100s;
proxy_connect_send_timeout 100s;
# forward proxy for non-CONNECT request
location / {
proxy_pass http://$http_host; # 这儿的设置可以解决代理非常规端口的问题
proxy_set_header Host $host;
}
}
参考: https://github.com/chobits/ngx_http_proxy_connect_module