web页面是https的,但是后台还是http的node服务没升级,所以导致前端请求http的ip端口浏览器会报错。
然后按照步骤升级node服务到https后
const express = require("express");
const app = express();
const https = require('https')
const http = require('http')
const fs = require('fs')
const bodyParser = require('body-parser')
const jwt= require('jsonwebtoken');
const expressJwt = require('express-jwt');
//根据项目的路径导入生成的证书文件
const privateKey = fs.readFileSync('/etc/letsencrypt/live/xxxx.xxx/privkey.pem', 'utf8');
const certificate = fs.readFileSync('/etc/letsencrypt/live/xxxx.xxx/cert.pem', 'utf8');
const ca = fs.readFileSync('/etc/letsencrypt/live/xxxx.xxx/chain.pem', 'utf8');
const credentials = {
key: privateKey,
cert: certificate,
ca: ca
};
var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);
//可以分别设置http、https的访问端口号
var PORT = 3001;
var SSLPORT = 3002;
//创建http服务器
httpServer.listen(PORT, function() {
console.log('HTTP Server is running on: http://localhost:%s', PORT);
});
//创建https服务器
httpsServer.listen(SSLPORT, function() {
console.log('HTTPS Server is running on: https://localhost:%s', SSLPORT);
});
但是 前端更改成https://172.XXX.XXX.XXX:3002浏览器会报错,但是postman没有问题
然后 如果在前端页面把 ip改成域名https://www.xxx.com:3002 就没问题 费解。。。
chrome的security如下