准备
关闭防火墙
systemctl stop firewalld
setenforce 0
一、配置nginx正向代理
1、下载ngx_http_proxy_connect_module 模块,Nginx 官方版本不支持 CONNECT,需安装 ngx_http_proxy_connect_module 模块
cd /usr/local
git clone https://github.com/chobits/ngx_http_proxy_connect_module.git
2、下载nginx源码包
通过网盘分享的文件:nginx-1.18.0.tar.gz
链接: https://pan.baidu.com/s/1pXSMVjriwaL4Ch0H9aOrRA?pwd=phx3 提取码: phx3
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar xf nginx-1.18.0.tar.gz
3、打补丁
通过网盘分享的文件:ngx_http_proxy_connect_module.tar.gz
链接: https://pan.baidu.com/s/1YOAqNTBPncU4lHBFz8bJsQ?pwd=bed1 提取码: bed1
cd nginx-1.18.0
patch -p1 < /usr/local/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1018.patch
#对应的版本补丁 1018对应nginx 1.18.0
4、编译安装模块
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-threads --with-stream --add-module=/usr/local/ngx_http_proxy_connect_module
make
make install
5、配置nginx http,https代理上网
cat > /usr/local/nginx/conf/nginx.conf <<'EOF'
worker_processes auto;
events {
worker_connections 1024;
}
http {
server {
listen 18088;
resolver 8.8.8.8 114.114.114.114 valid=30s; # 增加备用DNS和缓存时间
# 启用CONNECT方法(HTTPS代理)
proxy_connect;
proxy_connect_allow all; # 允许所有端口
proxy_connect_connect_timeout 10s;
proxy_connect_read_timeout 10s;
proxy_connect_send_timeout 10s;
location / {
proxy_pass http://$http_host$request_uri; # 使用$http_host更准确
proxy_set_header Host $host;
proxy_buffering off; # 禁用缓冲提高实时性
}
}
}
EOF
6、检查配置并启动nginx
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
7、客户端使用代理
配置完成后,客户端可通过以下方式使用代理:
Linux/Unix
export http_proxy=http://proxy_ip:18088
export https_proxy=http://proxy_ip:18088
没做代理之前
做了代理之后