써트봇 설치 및 도메인지정
sudo apt-get install certbot
sudo certbot certonly -d {Domain}
index.js
//================== SSL =============
if (process.env.NODE_ENV === "production") {
const fs = require("fs");
const https = require("https");
const privateKey = fs.readFileSync(
"/etc/letsencrypt/live/{Domain}/privkey.pem",
"utf8"
);
const certificate = fs.readFileSync(
"/etc/letsencrypt/live/{Domain}/cert.pem",
"utf8"
);
const ca = fs.readFileSync(
"/etc/letsencrypt/live/{Domain}/chain.pem",
"utf8"
);
const credentials = {
key: privateKey,
cert: certificate,
ca: ca,
};
// // ================ HTTPS 적용시 ===================
const httpsServer = https.createServer(credentials, app);
httpsServer.listen(port, () => {
console.log(`HTTPS {Domain} SERVER ${port}`);
});
} else {
console.log(`HTTP {Domain} SERVER :${port}`);
app.listen(port, () => {});
app.get("/", (req, res) => {
return res.send("{Domain} API");
});
}
// // ==============================================================
Crontab -e 로
0 0 1 * * sudo certbot renew
3달에 한번 갱신해주면 끄읏