openEuler 欧拉系统nginx正向代理 http https —— 筑梦之路

正向代理

Nginx正向代理,通过服务器代理客户端去重定向请求访问到目标服务器的一种代理服务。对于目标服务器来说浏览器/客户端是隐藏的。Nginx 正向代理默认只支持http 协议,不支持 https 协议,需借助"ngx_http_proxy_connect_module"模块实现https 正向代理。

GitHub - chobits/ngx_http_proxy_connect_module: A forward proxy module for CONNECT request handling

准备编译安装环境

bash 复制代码
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添加ngx_http_proxy_connect_module模块并重新编译nginx

bash 复制代码
wget -P /opt http://nginx.org/download/nginx-1.21.5.tar.gz

tar -xzvf /opt/nginx-1.21.5.tar.gz

cd /opt/nginx-1.21.5

patch -p1 <  /opt/ngx_http_proxy_connect_module-master/patch/proxy_connect_rewrite_102101.patch 

./configure --add-module=/opt/ngx_http_proxy_connect_module

make -j8 && make install
  • patch命令的用法,-p1 : 1代表跳过的层级数字

执行make & make install进行编译及安装(注意:如果已经yum/dnf安装nginx,执行make 后不要执行 make install)

配置文件示例

bash 复制代码
server {
       listen 8443;
       resolver  223.5.5.5 114.114.114.114 valid=300s;
       resolver_timeout 10s;
       #server_name localhost;
       proxy_connect;
       proxy_connect_allow 443 80;
       proxy_connect_connect_timeout 10s;
       proxy_connect_read_timeout 10s;
       proxy_connect_send_timeout 10s;

       location / {
        proxy_set_header Host $host;
        proxy_pass $scheme://$http_host$request_uri;
        proxy_buffers 256 4k;
        proxy_max_temp_file_size 0k;
        proxy_connect_timeout 30;
        proxy_send_timeout 60;
        proxy_read_timeout 60;
        proxy_next_upstream error timeout invalid_header http_502;

        }
}

测试代理

bash 复制代码
# 本机上测试

curl -I --proxy localhost:8443 http://nginx.org
curl -I --proxy localhost:8443 https://www.baidu.com
bash 复制代码
# linux客户端上测试

vim /etc/profile

export http_proxy=http://192.168.199.107:8443
export https_proxy=http://192.168.199.107:8443

# 全局代理

export ALL_PROXY='192.168.99.107:8443'

正向代理账户认证

bash 复制代码
htpasswd -c -d /etc/nginx/.passwd username


location /proxy-auth {
        auth_basic "secret";
        auth_basic_user_file  "/etc/nginx/.passwd";
 }



curl -I --proxy localhost:8443 http://nginx.org -U username:passwd
相关推荐
rainFFrain29 分钟前
Boost搜索引擎项目(详细思路版)
网络·c++·http·搜索引擎
2501_916007472 小时前
iOS App 上架实战 从内测到应用商店发布的全周期流程解析
android·ios·小程序·https·uni-app·iphone·webview
.Shu.2 小时前
计算机网络 HTTPS 全流程
网络协议·计算机网络·https
鹧鸪yy7 小时前
认识Node.js及其与 Nginx 前端项目区别
前端·nginx·node.js
猿究院--冯磊9 小时前
计算机网络--HTTP协议
网络协议·计算机网络·http
__lll_9 小时前
Nginx proxy_pass 404/502 根源:漏写末尾斜杠 / 的修复指南
nginx
让代码飞~10 小时前
idea进阶技能掌握, 使用自带HTTP测试工具,完全可替代PostMan
java·http·intellij-idea·postman
唐叔在学习1 天前
万字长文深度解析HTTPS协议
后端·https
Clownseven1 天前
Docker+Nginx+Node.js实战教程:从零搭建高可用的前后端分离项目
nginx·docker·node.js
Mr_Xuhhh1 天前
NAT、代理服务、内网穿透
网络·网络协议·http·https·udp·智能路由器