问题描述
以下内容似乎无济于事.
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选项.如前所述,您可以通过以下命令手动选择要使用的密钥和证书:
ng serve --ssl --ssl-key <key-path> --ssl-cert <cert-path>
如果您想为密钥和证书设置默认路径,则可以进入.angular-cli.json文件,相应地调整默认值"部分:
{
"$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,选项.
这篇关于通过HTTPS获取angular-cli进行投放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!