Nginx正向代理https

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

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