Nodejs 中带有 http-proxy 的 https 代理服务器(安全代理服务器)无法正常工作

2024-02-20

我需要设置一个 https 代理服务器(安全 Web 代理-http://dev.chromium.org/developers/design-documents/secure-web-proxy http://dev.chromium.org/developers/design-documents/secure-web-proxy)使用代理环境测试我的应用程序之一。

遵循的步骤: 1.借助http-proxy创建https代理服务器。代码,

    var https = require('https'),
    http = require('http'),
    util = require('util'),
    fs   = require('fs'),
    path = require('path'),
    colors = require('colors'),
    httpProxy = require('http-proxy'),
   // fixturesDir = path.join(__dirname, '..', '..', 'test', 'fixtures'),   
    httpsOpts = {
      key: fs.readFileSync('server.key', 'utf8'),
      cert: fs.readFileSync('server.crt', 'utf8')
    };

//
// Create the target HTTPS server
//
https.createServer(httpsOpts, function (req, res) {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.write('hello https\n');
  res.end();
}).listen(9010);

//
// Create the proxy server listening on port 8010
//
httpProxy.createServer({
  ssl: httpsOpts,
  target: 'https://localhost:9010',
  secure: false
}).listen(8010);

console.log('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8010'.yellow);
console.log('https server '.blue + 'started '.green.bold + 'on port '.blue + '9010 '.yellow);
  1. 创建包含 https 代理服务器详细信息的 PAC 文件
function FindProxyForURL(url, host) {    
  return "HTTPS 127.0.0.1:8010";
}
  1. 并将我的应用程序中的 pac 文件指向使用代理环境测试应用程序,示例代码粘贴在此处。
var url = require('url');
var https = require('https');
var PacProxyAgent = require('pac-proxy-agent');

// URI to a PAC proxy file to use (the "pac+" prefix is stripped)
var proxy = 'pac+http://localhost:123/hosted/pac.pac';
//console.log('using PAC proxy proxy file at %j', proxy);

// HTTP endpoint for the proxy to connect to
var endpoint = 'https://nodejs.org/api/';
//console.log('attempting to GET %j', endpoint);
var opts = url.parse(endpoint);

// create an instance of the `PacProxyAgent` class with the PAC file location
var agent = new PacProxyAgent(proxy,opts);
opts.agent = agent;

https.get(opts, function (res) {
  console.log('"response" event!', res.headers);
  res.pipe(process.stdout);
});

但它不起作用,它会抛出错误

Chrome 行为:

I configured the PAC file in windows proxy settings enter image description here

之后我没有收到任何网站的任何回复 例如:当我进入时https://gmail.com/ https://gmail.com/最终结果是

有什么建议么?


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Nodejs 中带有 http-proxy 的 https 代理服务器(安全代理服务器)无法正常工作 的相关文章

  • 如何模拟 typeorm 连接

    在集成测试中 我使用以下代码片段来创建连接 import Connection createConnection from typeorm ts ignore import options from ormconfig js export
  • Node + Express 与静态 HTML。如何将所有请求路由到index.html?

    我正在开发一个单页 Web 应用程序 使用 Node Express 和 Handlebars 进行模板化 目前 index html 的一切都运行良好 它由一个非常标准的 server js 文件提供 var express requir
  • 如何在 package.json 中对嵌套子模块和 TypeScript 使用“导出”?

    我想利用新的优势 出口 https nodejs org api packages html packages exportsNode js 的功能package json这样我就可以执行以下操作 exports dist index js
  • Node.js 有水豚吗?

    有谁知道 Node js 是否有类似 capybara 的东西 怎么样Zombie http zombie labnotes org 僵尸 js 使用 Node js 进行极其快速的无头全栈测试 The Bite 如果你要编写一个速度极快的
  • 节点检查器显示对象“无属性”

    我在调试场景中相当陌生 尤其是节点检查器 安装节点检查器后 我使用 debug 参数启动了简单的节点应用程序 并且能够在 localhost 8080 debug port 5858 处看到调试视图 当我让应用程序在此断点处停止时 rout
  • 以html格式显示npm审计漏洞

    有没有办法将 npm 审计报告显示为 html 页面 目前我只能看到使用以下命令以 json 格式输出报告的选项 npm audit json 我写了一个NPM包 https www npmjs com package npm audit
  • Typescript 和 Mongoose - “this”在实例方法中不可用

    我目前正在将我的 API 从 JS 转换为 TS 然而 我在猫鼬和打字稿方面遇到了一些困难 具体来说 this在我的实例方法中不可用 My code AccountSchema methods comparePassword async f
  • 使用 AWS Lambda 从 AWS S3 读取并提取巨大的 zip 文件

    我正在开发数据管理应用程序 客户可以上传zip file approx 250 MB 与多个text files approx 1500 MB on AWS S3 但由于记忆有限aws lamda 最大 1536MB 大小 我能够提取 50
  • 使用admin sdk在云函数中执行firestore集合组查询?

    firestore collectionGroup 方法在云函数中与 firebase admin sdk 一起使用时出现错误 是否可以在云函数中对 firestore 进行集合组查询 这是我尝试使用的 firestore 查询方法 htt
  • 如何让 Sinatra 通过 HTTPS/SSL 工作?

    正如标题所示 谷歌没有提供任何与此相关的有用信息 如何为 Sinatra 应用程序设置和配置 HTTPS SSL 如何创建 HTTPS 路由 我以前从未在我的应用程序中使用过 HTTPS 也没有调整 Rack 其他内容的经验 所以我很欣赏详
  • Child_process 处理带有回车符 (\r) 的 STDOUT 流

    我正在编写一个简单的应用程序 它允许工作中的内部系统请求从远程服务器到使用 REST 调用发起的另一个远程服务器的复制过程 使用 rsync 我已经对express框架足够熟悉 并且刚刚开始尝试child process库 并偶然发现了一个
  • Sequelize.js - “不关联到”

    我在从数据库获取完整数据时遇到一些问题 那是我的模型 User module exports function sequelize DataTypes return sequelize define user id type DataTyp
  • socket.io 作为客户端

    有什么方法可以将socketio作为客户端运行 不是浏览器 而是nodejs脚本 我需要将数据从服务器广播到一些客户端 浏览器 和另一台linux机器 仅运行nodejs来获取变量 没有浏览器 欢迎任何想法 Regards github上有
  • npm install 命令下载所需包的源位置是什么?

    我试图获取命令 npm install 尝试连接的源位置 URL 并根据 package json 文件获取要下载的依赖包 并将其放置在本地框中 从下面提到的网址 http www tutorialspoint com nodejs nod
  • 如何让WebClient(Web服务客户端)自动使用默认代理服务器?

    我正在从 WinForms 应用程序调用 Web 服务 当不使用代理服务器时 一切工作正常 但是当使用代理时 应用程序会崩溃 因为它收到的不是它期望的 SOAP 请求的 XML 响应 而是一个 HTML 错误页面 显示 需要身份验证 看来你
  • 护照:登录和帐户注册的不同重定向

    我在我的应用程序中使用护照模块 github身份验证 我想根据操作进行重定向 我检查这是否只是正常登录或者用户是否第一次登录 passport use new GitHubStrategy clientID conf github app
  • 从 HTTP 登录到 HTTPS

    我的网站默认使用 HTTP 我确实有一个启用 HTTPS 的证书 但只有其上的某些区域强制建立安全连接 登录是通过 Ajax 处理的 我想开始使用 SSL 即使请求来自 HTTP 我尝试强制请求的地址具有 HTTPS 并且它完美地回复 然而
  • 如何清除NPM的https代理设置?

    如何清除NPM之前的ssl代理设置 好吧 我搜索了很多 但我得到的所有帖子主要是关于如何set公司网络中的代理 我尝试将代理设置为空 npm config set http proxy npm config set https proxy
  • 为 Node.js 客户端应用程序保留 Firebase 用户

    我正在使用 Firebase 构建 Node js 命令行界面 CLI 用于与后端进行身份验证 我想避免让用户每次运行命令时都输入密码 相反 我想实现一个 登录 流程 将凭证保留到文件系统 该凭证可用于后续的无密码身份验证 直到用户 注销
  • 如何处理 MongoDB 的断开连接错误

    我在 Node js 进程中看到了这个未捕获的异常 Uncaught exception Error read ETIMEDOUT at TCP onStreamRead internal stream base commons js 16

随机推荐