Nginx正向代理

nginx正向代理默认是不支持https,如果想要通过正向代理访问https需要安装插件ngx_http_proxy_connect_module

安装ngx_http_proxy_connect_module插件

 

yum install git

git clone https://gitee.com/web_design_of_web_frontend/ngx_http_proxy_connect_module.git

 

这里需要选择下载路径,我直接下载在nginx安装目录下

设置参数(/root/nginx-1.18.0的路径根据自己的路径修改)

yum -y install patch

patch -p1 < /root/nginx-1.18.0/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1018.patch
 
编译模块
./configure --with-http_stub_status_module --with-http_sub_module   --with-http_auth_request_module --with-http_addition_module  --add-module=./ngx_http_proxy_connect_module


make && make install
 
修改nginx.conf正向代理参数
server {
      listen 80;
      resolver 8.8.8.8;       #DNS地址
      resolver_timeout 5s;    #配置代理超时时间
      proxy_connect;
      proxy_connect_allow 443 563;
      proxy_connect_connect_timeout 10s;
      proxy_connect_read_timeout 10s;
      proxy_connect_send_timeout 10s;
      location / {
          proxy_pass $scheme://$host$request_uri;
          proxy_set_header Host $http_host;
          proxy_buffers 256 4k;
          proxy_max_temp_file_size 0;
          proxy_connect_timeout 30;
      }
      access_log /usr/local/nginx/logs/access.log;
      error_log /usr/local/nginx/logs/error.log;
  }
 配置好后启动nginx即可
 
现在我们再来到没用外网的另外一台linux上
vi /etc/profile   #再最后面添加两行变量

export http_proxy="http://192.168.10.102:80"  #这里是我两台机器的内网ip,你们根据自己ip进行跟换

export https_proxy="http://192.168.10.102:80"

source /etc/profile   #使配置生效

curl https://www.baidu.com

curl http://www.baidu.com   #这个时候不管是使用http和https都可以访问外网

 

posted @   Try-to-shine_H  阅读(536)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示