Skip to content

Bun 은 BoringSSL 을 기반으로 TLS 를 기본적으로 지원합니다. TLS 를 활성화하려면 keycert 에 대한 값을 전달합니다. 둘 다 TLS 를 활성화하는 데 필요합니다.

ts
Bun.serve({
  tls: {
    key: Bun.file("./key.pem"), 
    cert: Bun.file("./cert.pem"), 
  },
});

keycert 필드는 TLS 키와 인증서의 경로가 아닌 콘텐츠 를 기대합니다. 이는 문자열, BunFile, TypedArray 또는 Buffer 일 수 있습니다.

ts
Bun.serve({
  tls: {
    key: Bun.file("./key.pem"), // BunFile
    key: fs.readFileSync("./key.pem"), // Buffer
    key: fs.readFileSync("./key.pem", "utf8"), // string
    key: [Bun.file("./key1.pem"), Bun.file("./key2.pem")], // 위 항목의 배열
  },
});

패스프레이즈

개인 키가 패스프레이즈로 암호화된 경우 passphrase 에 값을 제공하여 복호화합니다.

ts
Bun.serve({
  tls: {
    key: Bun.file("./key.pem"),
    cert: Bun.file("./cert.pem"),
    passphrase: "my-secret-passphrase", 
  },
});

CA 인증서

선택적으로 ca 에 값을 전달하여 신뢰할 수 있는 CA 인증서를 재정의할 수 있습니다. 기본적으로 서버는 Mozilla 가 선별한 잘 알려진 CA 목록을 신뢰합니다. ca 가 지정되면 Mozilla 목록이 덮어쓰여집니다.

ts
Bun.serve({
  tls: {
    key: Bun.file("./key.pem"), // TLS 키 경로
    cert: Bun.file("./cert.pem"), // TLS 인증서 경로
    ca: Bun.file("./ca.pem"), // 루트 CA 인증서 경로
  },
});

Diffie-Hellman

Diffie-Hellman 매개변수를 재정의하려면:

ts
Bun.serve({
  tls: {
    dhParamsFile: "/path/to/dhparams.pem", // Diffie Hellman 매개변수 경로
  },
});

서버 이름 표시 (SNI)

서버의 서버 이름 표시 (SNI) 를 구성하려면 tls 객체에서 serverName 필드를 설정합니다.

ts
Bun.serve({
  tls: {
    serverName: "my-server.com", // SNI
  },
});

여러 서버 이름을 허용하려면 tls 에 각각 serverName 필드가 있는 객체 배열을 전달합니다.

ts
Bun.serve({
  tls: [
    {
      key: Bun.file("./key1.pem"),
      cert: Bun.file("./cert1.pem"),
      serverName: "my-server1.com", 
    },
    {
      key: Bun.file("./key2.pem"),
      cert: Bun.file("./cert2.pem"),
      serverName: "my-server2.com", 
    },
  ],
});

Bun by www.bunjs.com.cn 편집