首先最重要的是 你要明白 https接口的接收或者发送 的形式 是  https://域名:端口号  
而不是 https://ip:端口号
 
一,首先,去阿里云注册免费ssl证书
 
1,在搜索框中输入关键字证书,点击SSL证书
 

2,点击购买证书

3,选择免费型,点击购买

4,点击支付

 5,点击确认支付

6,支付成功后进入证书控制台

 7,点击申请

8,填写信息,点击下一步,最后点击验证,等待审核结束。

9,证书下来之后进入阿里云证书管理控制台下载证书  (nginx),如图

 10,下载解压后文件中包含 .key和 .pem 两个文件。 (a.key是为了方便自定义的名称)

11,将下载解压后包含.key和 .pem 两个文件的文件夹上传到自己的项目中。

 

12,将以下代码复制粘贴到www文件中,https端口根据需求自己修改 

#!/usr/bin/env node
/**
 * Module dependencies.
 */
var app = require('../app');
var debug = require('debug')('demo:server');
var http = require('http');
var fs = require('fs')
var https = require('https')
var path = require('path')
var express = require('express')
const options = {
  key: fs.readFileSync(path.join(__dirname, '../cert/a.key')),
  cert: fs.readFileSync(path.join(__dirname, '../cert/a.pem'))
}
app.set('porthttps',11443)  
/**
 * Get port from environment and store in Express.
 */
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
/**
 * Create HTTP server.
 */
var server = http.createServer(app);
/**
 * Listen on provided port, on all network interfaces.
 */
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
https.createServer(options,app).listen(app.get('porthttps'),function(){
  console.log('11443端口运行');
})
/**
 * Normalize a port into a number, string, or false.
 */
function normalizePort(val) {
  var port = parseInt(val, 10);
  if (isNaN(port)) {
    // named pipe
    return val;
  }
  if (port >= 0) {
    // port number
    return port;
  }
  return false;
}
/**
 * Event listener for HTTP server "error" event.
 */
function onError(error) {
  if (error.syscall !== 'listen') {
    throw error;
  }
  var bind = typeof port === 'string'
    ? 'Pipe ' + port
    : 'Port ' + port;
  // handle specific listen errors with friendly messages
  switch (error.code) {
    case 'EACCES':
      console.error(bind + ' requires elevated privileges');
      process.exit(1);
      break;
    case 'EADDRINUSE':
      console.error(bind + ' is already in use');
      process.exit(1);
      break;
    default:
      throw error;
  }
}
/**
 * Event listener for HTTP server "listening" event.
 */
function onListening() {
  var addr = server.address();
  var bind = typeof addr === 'string'
    ? 'pipe ' + addr
    : 'port ' + addr.port;
  debug('Listening on ' + bind);
}

由衷感谢帮助我解决此问题的夏初秋博主  https://www.cnblogs.com/xiaqiuchu/

express 配置 https 服务 ( 以阿里云服务器为例), 探索一周终于搞定的更多相关文章

  1. Nginx 配置 HTTPS 完整过程(阿里云申请免费版一年ssl证书)

    1. nginx 的 ssl 模块安装 查看 nginx 是否安装 http_ssl_module 模块. $ /usr/local/nginx/sbin/nginx -V 如果出现 configur ...

  2. 阿里云服务器Linux CentOS安装配置(零)目录

    阿里云服务器Linux CentOS安装配置(零)目录 阿里云服务器Linux CentOS安装配置(一)购买阿里云服务器 阿里云服务器Linux CentOS安装配置(二)yum安装svn 阿里云服 ...

  3. 阿里云服务器发送邮件:Connection could not be established with host smtp.qq.com [Connection timed out #110]

    阿里云服务器发送邮件:Connection could not be established with host smtp.qq.com [Connection timed out #110] 一.总 ...

  4. 记录第一次阿里云服务器部署java web工程的经历

    起因:测试一个微信小程序,发现所有的请求要求为https的形式,开发工具忽略后手机无法测试,故尝试配置. 准备:阿里云服务器一台 域名一个(解析在服务器)     tomcat7.0.54     j ...

  5. 阿里云服务器linux主机如何添加swap分区

    为什么要添加Swap分区?swap分区,即交换区,作用为:当系统的物理内存不够用的时候,就需要将物理内存中的一部分空间释放出来,以供当前运行的程序使用.那些被释放的空间可能来自一些很长时间没有什么操作 ...

  6. 阿里云服务器 centos7 中继邮箱+转发服务 详细配置

    阿里云centos7 邮箱转发服务配置 一.文档编写目的: 网络拓扑图: 阿里云服务器屏蔽掉25端口后,内网服务器如何通过跳板机发送邮件到外网邮箱. 如果是可联网的阿里云机器,可以直接配置mailx使 ...

  7. 阿里云服务器CentOS6.9 tomcat配置https安全访问

    应用场景 上线微信小程序的时候,域名要求https安全格式,否则获取数据异常. 第一步.SSL证书获取 获取SSL证书方式很多种,包括网页生成.工具生成等,这里我使用阿里云平台获取免费ssl证书的方法 ...

  8. 阿里云服务器下安装LAMP环境(CentOS Linux 6.3) 安装与配置 Apache 服务

    想让我们的阿里云服务器成为一台 Web 服务器,我们需要安装一个 Web 服务器软件,比如 Apache ,或者 Nginx 等等.下面我们就一起来安装一个 Apache 服务. 我们可以使用 yum ...

  9. 阿里云服务器 配置 tomcat 发布spring boot项目 的具体操作 【使用公网ip】

    1.前言 spring boot 转成war包 后用tomcat发布的具体操作在我另一篇随笔有详细记载,不论是window系统还是Linux系统,tomcat的发布配置都是一样的,所以这里不具体讲这个 ...

随机推荐

  1. Python爬虫连载6-cookie深入使用实例化实现自动登录

    一.使用cookie登录 1.直接把cookie复制下去,然后手动放到请求头 2.http模块包含一些关于cookie的模块,通过他们我们可以自动使用cookie (1)cookieJar 管理存储c ...

  2. Python之时间和日期模块

    1.import time 先要导入时间模块 1)time.time()得到当前的时间,返回的是时间戳,表示自1970年1月1日起到程序运行时的秒数 import time print(time.ti ...

  3. Python - 模块中的"if __name__ == '__main__':"

    1.1 如果导入的模块除了定义函数之外还中有可以执行代码,那么Python解释器在导入这个模块时就会执行这些代码. module1.py: def foo(): print('module 1') f ...

  4. android的ListAdapter简单用法

    ListAdapter是一个整个Activity有且仅有一个ListView控件的Activity 使用步骤:1. 创建MyListViewAdapter(类名可以自定义) extends ListA ...

  5. MySQL(window10)加载配置文件的顺序

    mysql加载配置的顺序为:(mysql --help中有详细的说明) C:\WINDOWS\my.ini C:\WINDOWS\my.cnf C:\my.ini C:\my.cnf D:***\my ...

  6. oracle SQL 练习

    COURSE 表 DROP TABLE "SCOTT"."course"; CREATE TABLE "SCOTT"."cours ...

  7. 发送邮件#Python

    import yagmailusername='11@qq.com' #发件人邮箱qq='zhezlqiggd' #授权码,QQ邮箱可在设置账户获得mail_server='smtp.qq.com' ...

  8. 820算法复试 Eratasthene 质数筛选

    Eratasthene 学问之道无他,求其放心而巳矣 https://blog.csdn.net/qq_37653144/article/details/80470029 class Solution ...

  9. day21-Python运维开发基础(单个字符匹配 / 多字符匹配)

    1. 正则表达式(单个字符匹配) # ### 正则表达式 => 单个字符匹配 import re """ lst = re.findall(正则表达式,字符串) & ...

  10. IDEA导入项目后,导入artifacts 方法 以及 Spring的配置文件找不到的解决方法

    我们一般选择 open 项目,如果没有artifacts 的添加选项,我们就要选择 import 项目. 如果没有artifacts ,项目下面会有错误提示,点击错误提示Fix,设置里面导入artif ...