问题描述
以下似乎没有任何作用.
The following doesn't seem to do anything.
ng serve --ssl true --ssl-key <key-path> --ssl-cert <cert-path>
通过在默认 ssl 目录中提供证书和密钥来创建它们仍然没有任何作用.
Creating the Certificate and key by providing them in the default ssl directory still does nothing.
看起来 ng server
完全忽略了 --ssl
参数并一直说 NG Live Development Server is running on http://localhost:4200.
It looks like ng server
is completely ignoring the --ssl
parameter and keeps saying NG Live Development Server is running on http://localhost:4200.
推荐答案
Angular CLI 6+
我已经更新了我自己的项目,所以我想我现在也可以更新这个答案了.
Angular CLI 6+
I've updated my own projects so I figured I can now update this answer too.
您现在将在 angular.json 文件中放置密钥和证书的路径,如下所示:
You'll now put the path to your key and certificate in your angular.json file as follows:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"projects": {
"<PROJECT-NAME>": {
"architect": {
"serve: {
"options": {
"sslKey": "<relative path from angular.json>/server.key",
"sslCert": "<relative path from angular.json>/server.crt",
...
}, ...
}, ...
}, ...
}, ...
}, ...
}
然后你可以运行:
ng serve --ssl
如果您希望在默认情况下启用 SSL,那么您应该在 sslKey 和 sslCert 正下方添加一个 "ssl": true, 选项.
If you want SSL on by default then you should add a "ssl": true, option immediately below the sslKey and sslCert.
您可以在 Angular CLI 文档.
Angular-CLI 现在可以使用 SSL 选项.正如您所指出的,您可以手动选择要与命令一起使用的密钥和证书:
Angular-CLI now works with the SSL options. Like you've noted, you can manually select which key and cert you'd like to use with the command:
ng serve --ssl --ssl-key <key-path> --ssl-cert <cert-path>
如果你想为你的密钥和证书设置默认路径,那么你可以进入你的 .angular-cli.json 文件,相应地调整默认部分:
If you'd like to set a default path for your key and cert then you can go into your .angular-cli.json file adjust the Defaults section accordingly:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"defaults": {
"serve": {
"sslKey": "<relative path from .angular-cli.json>/server.key",
"sslCert": "<relative path from .angular-cli.json>/server.crt",
...
}, ...
}, ...
}
然后你可以运行:
ng serve --ssl
如果您希望在默认情况下启用 SSL,那么您应该在 sslKey 和 sslCert 正下方添加一个 "ssl": true, 选项.
If you want SSL on by default then you should add a "ssl": true, option immediately below the sslKey and sslCert.
这篇关于通过 HTTPS 获取 angular-cli 到 ng serve的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!