使用HTTP2返回的Vite代理“无法验证第一个证书”

发布于 2025-02-03 13:32:21 字数 1613 浏览 3 评论 0原文

我正在尝试使用VITE和本地后端的HTTP2请求来设置开发环境。我在Localhost上运行的客户端和服务器之间的代理请求。该服务器使用MKCERT使用生成证书( https://github.com/filosottile/mkcert )。

配置:

要配置证书我运行以下步骤:

  1. mkcert.exe -pkcs12“ test”“ 127.0.0.0.1”“ localhost”
  2. 配置后端使用生成的证书
  3. mkcert.exe -install
  4. 使用以下VITE配置:
server: {
  https: {
    pfx: fs.readFileSync(`./cert/test.pfx`),
    passphrase: "some-phrase",
  },
  proxy: {
    "/api": {
      target: `https://localhost:15000`,
      changeOrigin: true,
      secure: true,
    },
  },
},

当前此配置在Mac上起作用,但在Windows上失败。两者都使用相同的后端和证书,但是在Windows上,代理将失败:“无法验证第一个证书”。在浏览器中,证书链已正确验证。

故障排除:

当我运行openssl s_client -showcerts -showcerts -connect localhost:15000 -servername localhost查询导致“无法验证第一个证书”,也基本上表示MKCERT表示MKCERT根CA找不到正确的发现。

使用openssl s_client -showcerts -cafile“ c:\ users \ someuser \ appdata \ local \ local \ mkcert \ mkcert \ rootca.pem” -connect localhost:15000 -servername localhost localhost证书将得到正确验证。这应该表明代理缺乏对MKCERT的rootca的引用。

我尝试使用以下脚本在package.json中提供rootca:

“ dev”:“ cross-env node_extra_ca_cer_certs = \ \” c:\\ users \\ users \\ someuser \\ someuser \\ appdata local \\ mkcert \\ rootca.pem \“&& vite”,

这无济于事,而代理仍然会出现相同的错误。我认为Mac和Windows在向节点提供CA根证书时的工作方式有所不同,或者默默失败?

无论如何,这如何解决?我一直在考虑将完整的证书链提供给Vite的证书,但是如果节点可以正确地引用rootca,则不需要。

I am trying to setup a development environment using HTTP2 requests with Vite and a local backend. I proxy requests between client and server both running on localhost. The server is configured with a generated certificate using Mkcert (https://github.com/FiloSottile/mkcert).

Configuration:

To configure the certificate I run the following steps:

  1. mkcert.exe -pkcs12 "test" "127.0.0.1" "localhost"
  2. Configure the backend to use the generated cert
  3. mkcert.exe -install
  4. Use the following vite configuration:
server: {
  https: {
    pfx: fs.readFileSync(`./cert/test.pfx`),
    passphrase: "some-phrase",
  },
  proxy: {
    "/api": {
      target: `https://localhost:15000`,
      changeOrigin: true,
      secure: true,
    },
  },
},

Currently this configuration works on Mac but fails on Windows. Both use the same backend and certificates but on Windows the proxy will fail with: "unable to verify the first certificate". In the browser the certificate chain is a correctly validated.

Troubleshooting:

When I run openssl s_client -showcerts -connect localhost:15000 -servername localhost the query results in "unable to verify the first certificate" as well basically indicating that the mkcert Root CA isn't properly found.

Using openssl s_client -showcerts -CAfile "C:\Users\SomeUser\AppData\Local\mkcert\rootCA.pem" -connect localhost:15000 -servername localhost the certificates will be correctly validated. This should indicate that the proxy lacks a reference to the rootCA of Mkcert.

I have tried supplying the rootCA using the following script in package.json:

"dev": "cross-env NODE_EXTRA_CA_CERTS=\"C:\\Users\\SomeUser\\AppData\\Local\\mkcert\\rootCA.pem\" && vite",

This doesn't help however and the proxy still fails with the same error. I assume Mac and Windows work differently when supplying the CA root certs to Node or fails silently?

Anyway, how can this solved? I have been thinking about supplying the full cert chain in a cert that I supply to Vite, but this shouldn't be needed if Node could just reference the RootCA correctly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

×眷恋的温暖 2025-02-10 13:32:21

您需要为 Target 这样的CA配置:

https: true,
proxy: {
  '/api': {
    secure:false,
    changeOrigin: true,
    //TARGET
      target: {
        protocol:'https:',
        host:'videotest.lgh',
        port: 443,
        ca:  readFileSync('./src/key/CA.pem'),
      },
      rewrite: (path) => path.replace(/^\/api/, ''),
  }
}

Vite似乎不会使用Windows的Rootca Cert Store,因此我们需要自己配置它。

you need to configure ca for target like that:

https: true,
proxy: {
  '/api': {
    secure:false,
    changeOrigin: true,
    //TARGET
      target: {
        protocol:'https:',
        host:'videotest.lgh',
        port: 443,
        ca:  readFileSync('./src/key/CA.pem'),
      },
      rewrite: (path) => path.replace(/^\/api/, ''),
  }
}

Seems vite will not use Windows's rootCA cert store, so we need to configure it by ourselves.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文