使用Express搭建HTTPs加密服务器
来源:互联网 发布:编程技术流 编辑:程序博客网 时间:2024/04/29 22:37
1.生成证书文件
生成私钥key文件:
openssl genrsa 1024 > /文件路径/private.pem
通过私钥文件生成CSR证书签名:
openssl req -new -key /文件路径/private.pem -out /文件路径/csr.pem
通过私钥文件和CSR证书签名生成证书文件:
openssl x509 -req -days 365 -in /文件路径/csr.pem -signkey /文件路径/private.pem -out /文件路径/file.crt
2.修改启动文件
var fs = require('fs');var options = { key: fs.readFileSync('./文件路径/private.pem'), cert: fs.readFileSync('./文件路径/file.crt')};var https = require('https');var express = require('express');var app = express();app.use(express.static('public'));app.get('/about',function(req,res){ console.log(req.url); res.send('My name is chenYy');});app.get('/about/:kkkk',function(req,res){ console.log(req.url); res.send(req.params);});app.get('/about/:kkkk/:ppp',function(req,res){ console.log(req.url); res.send(req.params);});app.get('/chenyy/:ooo?',function(req,res){ console.log(req.params,req.url); //用end必须为string或Buffer //res.end(req.params.ooo); res.send(req.params);});app.get('/from/:name/to/:age',function(req,res){ console.log(req.url,req.params); res.json(req.params);});//app.set('views','../views');app.set('view engine','jade');app.get('/downloads',function(req,res){ res.send(req.ip);});
app.use(function(req,res){
console.log(req.url,req.params);
res.writeHead(200,{'Content-Type':'text/plain'});
res.end('Hello World!');
});
var server = https.createServer(options,app);
server.listen(8080);
0 0
- 使用Express搭建HTTPs加密服务器
- 使用Express搭建Web服务器
- express建立https服务器
- 使用nginx搭建https服务器
- 使用nginx搭建https服务器
- 使用nginx搭建https服务器
- 使用nginx搭建https服务器
- 使用nginx搭建https服务器
- 使用nginx搭建https服务器
- 使用nginx搭建https服务器
- 使用nginx搭建https服务器
- 使用 Nginx 搭建 HTTPS 服务器
- nodejs express服务器搭建和使用教程
- Nodejs+Express创建HTTPS服务器
- Nodejs+Express创建HTTPS服务器
- Nodejs+Express创建HTTPS服务器
- 搭建express服务器
- 【Nginx】使用nginx搭建https服务器
- 尼姆博弈之Matchs game
- android 利用mob 进行第三方登录
- TCP连接的“三次握手”与“四次挥手”
- Android 开发效率
- 关于ios中的转码问题
- 使用Express搭建HTTPs加密服务器
- 图文详解MyEclipse中新建Maven webapp项目的步骤(很详细)
- 计算机网络(网络层)
- 解决php的imagick库Strict Standards: Imagick::clone method is deprecated and it's use should be avoided
- HDU 3076 ssworld VS DDD 概率DP入门
- 万万没想到,公式还能这样编辑!
- gRPC 的协议分析
- R3;在32位进程中得到64位进程映像路径
- 汽车拐弯--三分法的应用1005