https://www.securesign.kr/guides/Node-js-SSL-Certificates-Install
https적용에는 2가지만 하면 된다. https모듈 불러오기, 적용하기
const https = require('https');
const options = {
ca: fs.readFileSync('/etc/letsencrypt/live/내블로그주소/fullchain.pem'),
key: fs.readFileSync('/etc/letsencrypt/live/내블로그주소/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/내블로그주소/cert.pem')
};
// Create an HTTPS service identical to the HTTP service.
https.createServer(options, app).listen(3030);
여기서 3030은 자신이 열고싶은 port를 의미한다.
express전체 적용모습
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
//
const https = require('https');
const http = require('http');
const fs = require('fs');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
// catch 404 and forward to error handler
app.use(function (req, res, next) {
next(createError(404));
});
// error handler
app.use(function (err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
// Create an HTTP service.
http.createServer(app).listen(3000);
const options = {
ca: fs.readFileSync('/etc/letsencrypt/live/내홈피주소/fullchain.pem'),
key: fs.readFileSync('/etc/letsencrypt/live/내홈피주소/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/내홈피주소/cert.pem')
};
// Create an HTTPS service identical to the HTTP service.
https.createServer(options, app).listen(3030);
따로 적용시킨 모습
var os = require('os');
var nodeStatic = require('node-static');
var http = require('http');
var socketIO = require('socket.io');
var https = require('https');
var fs = require('fs');
//var fileServer = new(nodeStatic.Server)();
http.createServer(function (req, res) {
//fileServer.serve(req, res);
var url = req.url;
if (req.url == '/') {
url = '/index.html';
}
if (req.url == '/favicon.ico') {
return res.writeHead(404);
}
res.writeHead(200);
res.end(fs.readFileSync(__dirname + url));
}).listen(8080);
const options = {
ca: fs.readFileSync('/etc/letsencrypt/live/techblogdevsan2.tk/fullchain.pem'),
key: fs.readFileSync('/etc/letsencrypt/live/techblogdevsan2.tk/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/techblogdevsan2.tk/cert.pem')
};
// Create an HTTPS service identical to the HTTP service.
var app = https.createServer(options, function (req, res) {
//fileServer.serve(req, res);
var url = req.url;
if (req.url == '/') {
url = '/index.html';
}
if (req.url == '/favicon.ico') {
return res.writeHead(404);
}
res.writeHead(200);
res.end(fs.readFileSync(__dirname + url));
}).listen(3030);
'프로그래밍 일반 > PHP' 카테고리의 다른 글
mongodb php 연결 (0) | 2020.05.29 |
---|---|
Node.js nodemon설정 (0) | 2020.05.28 |
[CSS] position : fixed 관련 문제 (0) | 2020.05.14 |
CSS개념잡기 (0) | 2020.05.14 |
[php] CK에디터 다운로드 미리보기 Lorem삭제하기 (0) | 2020.05.07 |