Nginx正向代理配置

Nginx 正向代理默认只支持 http 协议,不支持 https 协议,需借助 "ngx_http_proxy_connect_module" 模块实现 https 正向代理,详情请参考:

https://github.com/chobits/ngx_http_proxy_connect_module

安装Nginx某些模块会用到的系统类库

bash 复制代码
yum install -y dnf install libxml2 libxml2-devel libxslt-devel gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel patch perl-ExtUtils-Embed gd-devel geoip-devel gperftools gperftools-devel

一、下载 nginx

bash 复制代码
mkdir -p /opt/nginx && cd /opt/nginx
wget http://nginx.org/download/nginx-1.22.1.tar.gz
tar -xzvf nginx-1.22.1.tar.gz

二、下载 ngx_http_proxy_connect_module 模块

bash 复制代码
mkdir -p /opt/packages && cd /opt/packages
unzip ngx_http_proxy_connect_module-master.zip
mv ngx_http_proxy_connect_module-master /opt/packages/ngx_http_proxy_connect_module

三、编译安装 nginx

bash 复制代码
cd /opt/nginx/nginx-1.22.1/
patch -p1 < /opt/packages/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_102101.patch
./configure --add-module=/opt/packages/ngx_http_proxy_connect_module ...
make && make install

四、配置 nginx

vim conf/nginx.conf

bash 复制代码
    server {
        listen 8888;
        resolver 8.8.8.8 ipv6=off;
        proxy_connect;
        proxy_connect_allow 443 80;
        location / {
            proxy_pass $scheme://$http_host$request_uri;
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_connect_timeout 10;
            proxy_send_timeout 600;
            proxy_read_timeout 600;

        }
    }

五、重启 nginx。

注:`/sbin/nginx -s reload` 新增模块时重启有时不生效。

bash 复制代码
cd /opt/nginx/
./sbin/nginx -s stop
./sbin/nginx
相关推荐
知已难寻15 小时前
Docker 入门:容器技术与 Docker 基础
java·运维·服务器·docker·云原生·容器
Alluxio1 天前
Alluxio + OCI:为 AI 工作负载实现亚毫秒访问延迟与可扩展吞吐
运维·数据库·人工智能·分布式·缓存·ai·语言模型
Sayai1 天前
Neo4j 图数据质量检查实战:环路检测、孤立节点与连通分量,两条 Cypher 引出的数据体检清单(含变长路径性能陷阱)
运维·neo4j·图数据库·数据质量·cypher
Elastic 中国社区官方博客1 天前
更少的位数,相同的召回率:DiskBBQ 更保守的自动校准扫描
大数据·运维·开发语言·人工智能·elasticsearch·搜索引擎
方便面不加香菜1 天前
Docker Volume -- 管理卷Volume详解
运维·docker·容器
沫璃染墨1 天前
从零入门计算机网络系列(十八):TCP连接管理详解——从三次握手与四次挥手到TIME_WAIT机制
运维·服务器·网络·c++·网络协议·tcp/ip·tcp
Felven1 天前
华为鲲鹏920s芯片serdestool工具使用说明
linux·运维·服务器·华为·鲲鹏920·serdestool
江湖有缘1 天前
Docker实战 | 使用Docker部署lemonitor镜像站点列表程序
运维·docker·容器
莫晓燚1 天前
mall 电商项目完整部署---实战
linux·运维·docker·容器
爱和冰阔落1 天前
【Linux网络】JsonCpp 怎么实现序列化?从 Request/Response 到网络计算器消息设计
linux·运维·网络·php