> For the complete documentation index, see [llms.txt](https://jewelism.gitbook.io/boseok-note/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jewelism.gitbook.io/boseok-note/server-side/node.js/node-https.md).

# node에서 간편하게 letsencrypt를 사용하여 https 구현하는 방법

먼저 인증서를 생성합니다.

인증서를 생성하기위해서는 먼저 도메인이 필요한데, 해당 과정은 여기서는 생략합니다.

[ubuntu에서 letsencrypt 인증서발급방법](/boseok-note/server-side/letsencrypt.md)

greenlock 라이브러리를 사용합니다.

설명은 express기준으로 작성하였습니다만

express외에 koa, hapi 등의 모듈도 준비되어있습니다.

```bash
npm i greenlock-express
```

app.js에서,

```javascript
module.exports = app;
```

위의 코드 바로 전 라인에 아래 코드를 추가하면 된다.

```javascript
require('greenlock-express').create({
  version: 'draft-11',
  configDir: '/etc/letsencrypt/',
  server: 'https://acme-v02.api.letsencrypt.org/directory',
  email: '이메일',
  agreeTos: true,
  approvedDomains: ['도메인'],
  app,
  renewWithin: 81 * 24 * 60 * 60 * 1000,
  renewBy: 80 * 24 * 60 * 60 * 1000,
}).listen(80, 443);
```

reference : <https://git.coolaj86.com/coolaj86/greenlock-express.js>

또 다른방법은 nginx로 reverse proxy를 구현하고, ssl을 붙이는 방법이 있긴하다. 그런데 위에 방법이 더 간편함..


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jewelism.gitbook.io/boseok-note/server-side/node.js/node-https.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
