simple and free http2 with express | 简单免费给express升级http2
if you are not using certbot, skip this | 如果你不使用certbot,跳过此步骤
point your domain to your server | 将域名指向要部署的服务器
certbot certonly
see full conversation here | 查看命令对话详情
npm install certbot-express
const express = require('express')
const { redirect, http2 } = require('certbot-express')
const app = express()
const certDir = '/etc/letsencrypt/live/test.i18ntech.com/' // you can get certDir from env
const dev = process.env.NODE_ENV !== 'production'
app.use(redirect)
app.use('/', (req, res) => {
res.send('http2!')
})
http2({
dev, //if dev is true only http is served, all about http2 are skipped
certDir,
app,
}).listen().then(() => {
console.log('server started')
}).catch((e) => {
console.log(e)
})
or | 或者
http2({
keyPath:'/etc/letsencrypt/live/test.i18ntech.com/privkey.pem',
certPath:'/etc/letsencrypt/live/test.i18ntech.com/fullchain.pem'
app,
})
it might be something like this, you can add it to your cron job
certbot renew --pre-hook "forever stop app.js" --post-hook "forever start app.js"