运行 具有自定义开发证书的 Webpack 开发服务器

Running Webpack dev server with custom dev certificates

我正在使用 webpack 开发服务器,我想将它与 https 一起使用,所以我在 guide.

之后创建了一个自签名证书

为了在地址https://localhost上使用,默认的就可以了。但是我必须包含域名 (localhost.myDomain),然后证书就不能再正确生成了。

我得到了:

PEM 文件

-----BEGIN CERTIFICATE-----
MIIFcjCCA1qgAwIBAgIUAYol2crIjvJ8wv8ZiGcL25ZY/nMwDQYJKoZIhvcNAQEL
BQAwWzELMAkGA1UEBhMCR0IxFjAUBgNVBAgMDUdyZWF0IEJyaXRhaW4xDzANBgNV
BAcMBkxvbmRvbjEPMA0GA1UECgwGU2VxdWVsMRIwEAYDVQQDDAlsb2NhbGhvc3Qw
HhcNMjAwMjI2MTMwNjAzWhcNNDAwMTAyMTMwNjAzWjBbMQswCQYDVQQGEwJHQjEW
MBQGA1UECAwNR3JlYXQgQnJpdGFpbjEPMA0GA1UEBwwGTG9uZG9uMQ8wDQYDVQQK
DAZTZXF1ZWwxEjAQBgNVBAMMCWxvY2FsaG9zdDCCAiIwDQYJKoZIhvcNAQEBBQAD
ggIPADCCAgoCggIBANRcWZzQN9yacv9Yu3dfsvfaZm6H2sfh3mbpSTe0u/ZD9Nkp
V+LXP6WnvPP7C4Y3pvCjGXBmPaCoI5u4aT2WVkvKQ9DFqGqGxFNGr4jU2sb0cnV1
KN6tzHOoHDu1btZyd2ZVKK1M69g6dUW4GregiOTEkFEg/s1W87EWNIt1pQ3mnFbH
IDtHRQFwFBfg1sVDqoCBpMRJni/EsVp4qEHFAO/6oB7mYDxn+jIdNR0az/Rk8VtG
q5XzT5gbjgmO/aALgR8LuWCqRo0/ui3dzq5Jv9A3VFrRjbHFgUqD05QjORvKTFMg
vRV1Z1YHbundIq34ilLTIzaNHmkGCl+3ZCDCDtsDk2OziRHZPo9k/GBcbVx3dVl/
Pe0p529N1oBsXoFW/PBtmbZ8ADFGyOBE5hXHzJeu6Q5km5lGFQ5t66nXcE56r7qu
u7Yvj+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"concurrently \"webpack-dev-server --env=dev --open --hot --inline --host localhost.myDomain --https --cert localDev.pem --key localDev.key\" \"dotnet run\" "

我已确保将 pem 和密钥文件转换为 BOM-8,并将 CR 转换为 CRLF,但无济于事。我不断收到此错误

[1] [11:46:06 INF] [0] Begin compile at 11:46:06 GMT+0000 (Greenwich Mean Time)
[1]
[1] [11:46:06 INF] [0] Error: error:0909006C:PEM routines:get_name:no start line
[1]
[1] [11:46:06 INF] [0]     at Object.createSecureContext (_tls_common.js:130:17)
[1] [0]     at Server.setSecureContext (_tls_wrap.js:1155:27)
[1] [0]     at Server (_tls_wrap.js:1033:8)
[1] [0]     at new Server (https.js:65:14)
[1] [0]     at Object.createServer (https.js:89:10)

有什么想法吗?

编辑:

我看过

openssl x509 -text -in localDev.pem 

returns 预期的证书,但是

openssl x509 -text -in localDev.key

Returns

 140427202538824:error:0909006C:PEM routines:get_name:no start line:crypto/pem/pem_lib.c:745:Expecting: TRUSTED CERTIFICATE

(openssl rsa -text -in localDev.key返回正确内容)

会不会是这个原因? webpack dev server 不期望密钥上有 rsa 吗?

事实证明 webpack-dev-server 不喜欢有“.”。在路径中(我的项目名称中有一些 My.Solution.Project)。

我已经尝试从 c:\temp\security 获取 pem、密钥和 crt,并且成功了。如果我将目录更改为 c:\temp\security\Users.1,它将停止工作并给出上述错误。

作为准备步骤,我会将文件复制到 c:\temp\security。