Nginx支持正向代理http协议,但是不支持https协议,如果需要Nginx实现https协议的正向代理,需要使用第三方模块。
参考地址:
https://blog.csdn.net/weixin_43834401/article/details/130670792
Nginx下载地址:https://nginx.org/en/download.html
第三方模块下载地址:https://github.com/chobits/ngx_http_proxy_connect_module/releases
安装
cd /usr/local/src
将Nginx和第三方模块下载到当前目录
解压
tar xf nginx-1.25.3.tar.gz
unzip ngx_http_proxy_connect_module-master.zip
cd nginx-1.25.3
需要先打补丁,否则后面编译会报错,参考模块github官网信息
patch -p1 < ../ngx_http_proxy_connect_module-master/patch/proxy_connect_rewrite_102101.patch
./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx.pid --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-threads --add-module=/usr/local/src/ngx_http_proxy_connect_module-master
make && make install
编辑Nginx配置文件
vim /usr/local/nginx/conf/nginx.conf
清空输入内容:
events { worker_connections 1024; } http { # 在这里定义 main 日志格式 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; server { listen 80; server_name localhost; resolver 114.114.114.114 ipv6=off; proxy_connect; proxy_connect_allow 443 80; proxy_connect_connect_timeout 10s; proxy_connect_data_timeout 10s; # 指定代理日志 access_log logs/access_proxy.log main; location / { proxy_pass $scheme://$host$request_uri; } } }View Code
验证配置
/usr/local/nginx/sbin/nginx -t
启动服务
/usr/local/nginx/sbin/nginx
测试
curl -x http://127.0.0.1:80 http://www.baidu.com
curl -x http://127.0.0.1:80 https://www.baidu.com
标签:http,nginx,module,Nginx,proxy,https,正向,connect From: https://www.cnblogs.com/wilsonisnotascapegoat/p/17983955