首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用Windows身份验证*和HTTPS*配置ng服务代理

如何使用Windows身份验证*和HTTPS*配置ng服务代理
EN

Stack Overflow用户
提问于 2020-11-16 17:38:33
回答 1查看 1.2K关注 0票数 0

我想将ng serve与带有Windows身份验证 (NTLM)保护的后端服务器一起使用。这与这些帖子(example 1example 2)中的情况差不多,只是服务器是通过HTTPS访问的。

当我尝试使用相同的解决方案(HTTP很好)时,我会得到一个404错误(当然,服务器在这个URL上是可以访问的,我可以直接用浏览器进行测试)。

代码语言:javascript
运行
复制
const Agent = require("agentkeepalive");

module.exports = {
    '/api': {
        target: "https://my-server.example.com",
        secure: false,
        changeOrigin: true,
        agent: new Agent({
            maxSockets: 100,
            keepAlive: true,
            maxFreeSockets: 10,
            keepAliveMsecs: 100000,
            timeout: 6000000,
            keepAliveTimeout: 90000
        }),
        onProxyRes: proxyRes => {
            const key = "www-authenticate";
            proxyRes.headers[key] = proxyRes.headers[key] &&
                proxyRes.headers[key].split(",");
        }
    }
}

任何帮助都将不胜感激,包括一些诊断问题的方法。

UPDATE:使用logLevel = "debug“,我得到了以下堆栈跟踪(我不理解这一点,因为如果不是Windows,相同的代理配置在HTTPS中工作得很好):

代码语言:javascript
运行
复制
TypeError [ERR_INVALID_PROTOCOL]: Protocol "https:" not supported. Expected "http:"
    at new ClientRequest (_http_client.js:119:11)
    at Object.request (https.js:289:10)
    at Array.stream (C:\myproject\node_modules\http-proxy\lib\http-proxy\passes\web-incoming.js:126:74)      
    at ProxyServer.<anonymous> (C:\myproject\node_modules\http-proxy\lib\http-proxy\index.js:81:21)
    at middleware (C:\myproject\node_modules\http-proxy-middleware\lib\index.js:46:13)
    at handle (C:\myproject\node_modules\webpack-dev-server\lib\Server.js:322:18)
    at app.use (C:\myproject\node_modules\webpack-dev-server\lib\Server.js:330:47)
    at Layer.handle_error (C:\myproject\node_modules\express\lib\router\layer.js:71:5)
    at trim_prefix (C:\myproject\node_modules\express\lib\router\index.js:315:13)
    at C:\myproject\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\myproject\node_modules\express\lib\router\index.js:335:12)
    at next (C:\myproject\node_modules\express\lib\router\index.js:275:10)
    at Layer.handle [as handle_request] (C:\myproject\node_modules\express\lib\router\layer.js:97:5)
    at trim_prefix (C:\myproject\node_modules\express\lib\router\index.js:317:13)
    at C:\myproject\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\myproject\node_modules\express\lib\router\index.js:335:12)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-16 18:10:04

通常,当我在经过几天的挣扎之后,在Stack溢出上发布一个问题时,我会在接下来的一个小时内自己找到解决方案.

问题是,Agent只适用于HTTP。对于HTTPS,我们必须使用HttpsAgent

代码语言:javascript
运行
复制
const HttpsAgent = require('agentkeepalive').HttpsAgent;

module.exports = {
    '/api': {
        target: "https://my-server.example.com",
        secure: false,
        changeOrigin: true,
        agent: new HttpsAgent({
            maxSockets: 100,
            keepAlive: true,
            maxFreeSockets: 10,
            keepAliveMsecs: 100000,
            timeout: 6000000,
            keepAliveTimeout: 90000
        }),
        onProxyRes: proxyRes => {
            const key = "www-authenticate";
            proxyRes.headers[key] = proxyRes.headers[key] &&
                proxyRes.headers[key].split(",");
        }
    }
}
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64862939

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档