首页 > 系统相关 >Nginx正向代理https

Nginx正向代理https

时间:2024-01-24 09:55:54浏览次数:48  
标签:http nginx module Nginx proxy https 正向 connect

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

相关文章

  • 44从零开始用Rust编写nginx,命令行参数的设计与解析及说明
    wmproxywmproxy已用Rust实现http/https代理,socks5代理,反向代理,静态文件服务器,四层TCP/UDP转发,七层负载均衡,内网穿透,后续将实现websocket代理等,会将实现过程分享出来,感兴趣的可以一起造个轮子项目地址国内:https://gitee.com/tickbh/wmproxygithub:https://github.com/......
  • nginx配置支持ws,并解决跨域
    修改配置文件nginx.confserver{listen443ssl;server_nameexcalidraw.haimaotv.com;ssl_certificate/opt/nginx-1.24.0/excalidraw.haimaotv.com_bundle.crt;ssl_certificate_key/opt/nginx-1.24.0/excalidraw.haimaotv.com.key;ssl_se......
  • Nginx视频地址配置
    #视频资源地址location/video/{add_headerAccess-Control-Allow-Origin*;add_headerAccess-Control-Allow-Methods'GET,POST,OPTIONS';add_headerAccess-Control-Allow-Headers'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-R......
  • .NET Framework 4 请求https接口
    usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;usingSystem.Net;usingSystem.Text;usingSystem.Web;usingNewtonsoft.Json;namespaceTest.A{publicstaticclassHttpHelper{publicstaticTPostHttp......
  • 浏览器http自动跳转https解决方法
    在某个浏览器用https登录过之后,浏览器会自动改为https访问,导致测试环境进不去,需要删除hsts,不同浏览器的处理办法为:IE浏览器1.地址栏中输入edge://net-internals/#hsts2.在Deletedomain中输入项目的域名,并Delete(删除)3.可以在Querydomain测试是否删除成功。Chrome浏览器1.地......
  • nginx 替换访问路径前缀
    可以使用nginx的rewrite模块来替换访问路径前缀。例如,将所有以“/api”开头的请求转发到后端服务器,并将“/api”替换为“/backend”,可以在nginx配置文件中添加以下规则: location/api{rewrite^/api(.*)$/backend$1break;proxy_passhttp://backend-server;} 这样,当......
  • Nginx配置ThinkPHP3.1的PATHINFO模式
    server{listen8156;#监听端口(根据自己的需求更改)server_namelocalhost;#域名root/www/php;indexindex.htmlindex.htmindex.php;location~.*\.php/?.*${fastcgi_indexindex.php;fastcgi_pass127.0.0.1:9000;includefa......
  • https://github.com/runze1223/VH-NBEATS 时序数据NBEATS
    https://github.com/runze1223/VH-NBEATS http://ise.thss.tsinghua.edu.cn/~mlong/doc/TimesNet-iclr23.pdf  https://www.xjx100.cn/news/6779.html  https://blog.csdn.net/qq_59482564/article/details/134912580 https://blog.csdn.net/qq_59482564/arti......
  • npm ERR! request to https://registry.npm.taobao.org/axios failed, reason: certif
    前言一直使用npmbuild没问题的,突然出现报错:npmWARNinstallUsageofthe`--dev`optionisdeprecated.Use`--only=dev`instead.npmERR!codeCERT_HAS_EXPIREDnpmERR!errnoCERT_HAS_EXPIREDnpmERR!requesttohttps://registry.npm.taobao.org/axiosfailed,......
  • nginx rewrite
    server{listen443ssl;listen[::]:443ssl;server_namelocalhost;ssl_certificatecert/server.crt;ssl_certificate_keycert/server.key;location/{root/usr/share/nginx/html;indexindex.htmlinde......