1.1 tomcat配置SSL证书
tomcat配置
# 上传证书
cp ../bonc.com.cn.jks ./conf/
# 修改配置
server.xml
<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
keystoreFile="conf/domains.jks"
keystorePass="80ISkH7c" //证书密钥 ,密码文本那个
clientAuth="false" sslProtocol="TLS" />
<Connector port="8088" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" keystoreFile="/data01/bonc_zj/bonc_web/tomcat/ssl/bonc.com.cn.jks" keystorePass="bonc" clientAuth="false" sslProtocol="TLS" connectionTimeout="20000" maxHttpHeaderSize="81920" relaxedQueryChars="<>[\]{|}" URIEncoding="utf-8" />
# 修改配置
web.xml
<login-config>
<!-- Authorization setting for SSL -->
<auth-method>CLIENT-CERT</auth-method>
<realm-name>Client Cert Users-only Area</realm-name>
</login-config>
<security-constraint>
<!-- Authorization setting for SSL -->
<web-resource-collection >
<web-resource-name >SSL</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
1.2 node.js 配置SSL证书
node.js 配置SSL证书
101.71.102.255
/home/bonc_zj/java_web/wisdom-study/wisdom-study
# 上传SSL证书
./ssl/bonc.com.cn.key
./ssl/bonc.com.cn.pem
代码修改
# ########################################## 代码 ####################################
/** 用于开发环境的服务启动 **/
const path = require("path"); // 获取绝对路径有用
const express = require("express"); // express服务器端框架
// const http = require("http");
const https = require("https");
const fs = require("fs");
const httpsOption = {
key : fs.readFileSync(__dirname + "/ssl/bonc.com.cn.key"),
cert: fs.readFileSync(__dirname + "/ssl/bonc.com.cn.pem")
}
const compression = require("compression");
const app = express(); // 实例化express服务
// const PORT = 8088; // 服务启动端口号
app.use(compression());
// http.createServer(app).listen(80);
/** express 跨域中间件 **/
const allowCrossDomain = function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*"); //自定义中间件,设置跨域需要的响应头。
res.header("Access-Control-Allow-Headers", "Content-Type");
res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
res.header("Access-Control-Allow-Credentials", "true");
next();
};
app.use(allowCrossDomain); //运用跨域的中间件
/** express 跨域中间件 **/
// 如果是生产环境,则运行build文件夹中的代码
app.use(express.static("dist"));
app.get("*", function(req, res) {
res.sendFile(path.join(__dirname, "dist", "index.html"));
});
/** express 404 错误处理 **/
app.use(function(req, res, next) {
var err = null;
try {
decodeURIComponent(req.path);
} catch (e) {
err = e;
}
if (err) {
return res.redirect(["http://", req.get("Host"), "/404"].join(""));
}
next();
});
/** 启动服务 **/
// app.listen(PORT, () => {
// console.log("本地服务启动地址: http://localhost:%s", PORT);
// });
https.createServer(httpsOption, app).listen(8088);
1.3 nginx配置
nginx配置
标签:配置,const,证书,res,app,express,SSL,bonc
From: https://www.cnblogs.com/route/p/17389488.html