You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular本地HTTPS服务无法访问:localhost拒绝连接问题求助

本地Angular HTTPS启动连接失败的排查与解决

1. 修复angular.json语法错误

你提供的配置存在语法问题:browserTarget行末尾缺少逗号,这会导致Angular无法正确读取SSL配置。修正后的配置如下:

"serve": {
  "builder": "@angular-devkit/build-angular:dev-server",
  "options": {
    "browserTarget": "app.com:build",
    "sslKey": "src/localhost.key",
    "sslCert": "src/localhost.crt"
  }
}

2. 验证SSL证书有效性

  • 确认src/localhost.key和src/localhost.crt文件确实存在于项目src目录下,文件名和路径完全匹配配置项
  • 用以下命令验证证书与密钥是否配对:
    # 验证密钥模数
    openssl rsa -noout -modulus -in src/localhost.key | openssl md5
    # 验证证书模数
    openssl x509 -noout -modulus -in src/localhost.crt | openssl md5
    
    两个命令的输出必须完全一致,否则证书和密钥不匹配,需要重新生成。

3. 检查端口占用

确认44314端口未被其他程序占用:

  • Windows系统:
    netstat -ano | findstr :44314
    
  • Mac/Linux系统:
    lsof -i :44314
    
    如果端口被占用,更换一个未被使用的端口(比如44300)重新启动。

4. 清理缓存并重新启动

执行以下命令清理Angular缓存后重新启动服务:

ng clean && ng serve --port 44314 --ssl true

也可以直接依赖angular.json中的SSL配置,省略命令行的--ssl true参数:

ng serve --port 44314

5. 浏览器端排查

  • 使用浏览器隐身模式访问https://localhost:44314,避免缓存或插件干扰
  • 如果浏览器提示证书不安全,手动将localhost.crt安装到系统的信任根证书颁发机构列表中

内容的提问来源于stack exchange,提问作者Palani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 17:10:36