NGINX Unit SSL/TLS certificates
NGINX Unit /control API의 /certificates 섹션은 Unit의 Listener와 함께 사용되는 TLS 인증서를 처리합니다.
NGINX Unit 의 리스너에 대해 SSL/TLS를 설정하려면, 인증서 체인과 개인 키가 포함된 .pem 파일을 Unit에 업로드하고, 리스너의 구성에서 업로드된 번들의 이름을 지정하십시오. 그 다음, 해당 리스너에 SSL/TLS를 통해 접근할 수 있습니다.
먼저, 인증서 체인과 개인 키가 포함된 .pem 파일을 생성합니다.
cat cert.pem ca.pem key.pem > bundle.pem
일반적으로 웹사이트의 인증서(필요에 따라 중간 CA 인증서 포함)만으로도 인증서 체인을 구축할 수 있습니다. 체인에 더 많은 인증서를 추가하려면 leaf부터 root까지 순서대로 배치하세요.
생성된 번들 파일을 적절한 이름(이 경우, bundle)으로 Unit의 인증서 저장소에 업로드합니다.
curl -X PUT --data-binary @bundle.pem --unix-socket \
/path/to/control.unit.sock http://localhost/certificates/bundle
{
"success": "Certificate chain uploaded."
}
경고:
curl을 사용하여 파일을 업로드할 때 -d 옵션을 사용하지 마십시오. 이 옵션은 .pem 파일을 손상시킵니다. 파일 기반 데이터를 업로드할 때 데이터 손상을 방지하기 위해 –data-binary 옵션을 사용하세요.
Unit 내부에서는 업로드된 인증서 번들을 다른 구성 데이터와 함께 state 하위 디렉토리에 저장합니다. control API는 /certificates를 사용하여 GET 테이블 JSON으로 일부 속성을 노출합니다
{
"certificates": {
"bundle": {
"key": "RSA (4096 bits)",
"chain": [
{
"subject": {
"common_name": "example.com",
"alt_names": [
"example.com",
"www.example.com"
],
"country": "US",
"state_or_province": "CA",
"organization": "Acme, Inc."
},
"issuer": {
"common_name": "intermediate.ca.example.com",
"country": "US",
"state_or_province": "CA",
"organization": "Acme Certification Authority"
},
"validity": {
"since": "Sep 18 19:46:19 2022 GMT",
"until": "Jun 15 19:46:19 2025 GMT"
}
},
{
"subject": {
"common_name": "intermediate.ca.example.com",
"country": "US",
"state_or_province": "CA",
"organization": "Acme Certification Authority"
},
"issuer": {
"common_name": "root.ca.example.com",
"country": "US",
"state_or_province": "CA",
"organization": "Acme Root Certification Authority"
},
"validity": {
"since": "Feb 22 22:45:55 2023 GMT",
"until": "Feb 21 22:45:55 2026 GMT"
}
}
]
}
}
}
참고:
체인 내 개별 인증서와 그 속성에 액세스하려면 인덱싱을 통해 접근하세요.
curl -X GET --unix-socket /path/to/control.unit.sock \
http://localhost/certificates/bundle/chain/0/
curl -X GET --unix-socket /path/to/control.unit.sock \
http://localhost/certificates/bundle/chain/0/subject/alt_names/0/
다음으로, 업로드된 번들을 리스너에 추가합니다. 결과적으로 control API 구성은 다음과 같이 보일 수 있습니다.
{
"certificates": {
"bundle": {
"key": "<key type>",
"chain": [
"<certificate chain, omitted for brevity>"
]
}
},
"config": {
"listeners": {
"*:443": {
"pass": "applications/wsgi-app",
"tls": {
"certificate": "bundle"
}
}
},
"applications": {
"wsgi-app": {
"type": "python",
"module": "wsgi",
"path": "/usr/www/wsgi-app/"
}
}
}
}
이제 애플리케이션은 SSL/TLS를 통해 접근할 수 있습니다.
curl -v https://127.0.0.1
...
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / AES256-GCM-SHA384
...
마지막으로, 더 이상 필요하지 않은 인증서 번들은 저장소에서 삭제할 수 있습니다.
curl -X DELETE --unix-socket /path/to/control.unit.sock \
http://localhost/certificates/bundle
{
"success": "Certificate deleted."
}
참고:
구성에서 참조된 인증서 번들은 삭제할 수 없으며, put을 사용하여 기존 번들을 덮어쓸 수 없고, 존재하지 않는 번들을 삭제할 수도 없습니다.