728x90
๐จ Error :
๐ก NGINX์ ssl ์ ์ฉ์ ํ ์คํธํ๋๋ฐ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ค.
๐ nginx.conf ์ผ๋ถ
http {
ssl_certificate /path/
ssl_certificate_key /path/
server {
listen 8080 ssl;
server_name test;
...
}
...
}
- ssl_certificate์๋ ์ธ์ฆ์์ ๊ฒฝ๋ก๋ฅผ ์ ๊ณ , ssl_certificated_key์๋ ํด๋น ์ธ์ฆ์์ ๊ฐ์ธ ํค ํ์ผ ๊ฒฝ๋ก๊ฐ ๋ค์ด๊ฐ์ผ ํ๋ค.
- ์ด๋ฅผ ํตํด NGINX ์๋ฒ์ HTTPS ์ฐ๊ฒฐ์ ์ค์ ํ๊ณ ์ํธํ๋ ํต์ ์ ์ ์ฉํ ์ ์๋ค.
- ์์ ์ ๋ง์น๊ณ ๋ก์ปฌ ์๋ฒ์ ํฌ๋กฌ ๋ธ๋ผ์ฐ์ ์์ ํด๋น์๋ฒ๋ก HTTPS ์ ์์ ์๋ํ๋๋ ์ฑ๊ณตํ๋ค.
- Postman์ผ๋ก๋ POST, GET ์์ฒญ์ ๋ณด๋๋๋ฐ ์ ๋๊ธธ๋ ์ ์์ ์ผ๋ก ์๋๋๋ ์ค ์์๋ค.
๋ง์ง๋ง์ผ๋ก ์คํ๋ง ๋ถํธ ์๋ฒ ๊ฐ์ ํต์ ์ ํ ์คํธํ๋๋ฐ...
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at java.base/sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
at java.base/sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
at java.base/java.security.cert.CertPathBuilder.build(CertPathBuilder.java:297)
at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:434)
- ์์ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.
- ํด๋น ์ธ์ฆ์์ ๋ํ ๊ฒ์ฆ์ ์คํจํ ๋ฏํ๋ค.
- ํด๋น ์คํ๋ง ๋ถํธ ์๋ฒ๊ฐ ์๋ ์ค์ธ ์ธ์คํด์ค์์ curl ๋ช ๋ น์ด๋ก ์ ์์ ์๋ํด ๋ณด์๋ค.
curl: (60) Peer's Certificate issuer is not recognized.
More details here: http://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.
- ์ธ์ฆ์๋ฅผ ๋ฐ๊ธํ CA์ ๊ฒ์ฆ์ด ์คํจํ๋ค๊ณ ๋์๋ค.
- ๊ทธ๋์ nginx๊ฐ ์ค์น๋ ์๋ฒ์์๋ curl ๋ช
๋ น์ด๋ก HTTPS ์ ์์ ์๋ํ๋ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.
- ๋ ์๋ฒ ๋ชจ๋ CENTOS7์ด๋ค.
- ๋ก์ปฌ PC์ ํฌ๋กฌ ๋ธ๋ผ์ฐ์ ๋ ํฌ์คํธ๋งจ์์๋ ์ ์์ด ๋๋๋ฐ ์ธ์คํด์ค ์๋ฒ์์๋ ์ ์์ด ๋์ง ์์๋ค.
- ๋์ฑ์ด ๊ธฐ์กด์ ์คํ๋ง๋ถํธ ์๋ฒ์ application.properties์ ssl ์ ์ฉ์ ํ์ ๋๋ ํด๋น ๋ฌธ์ ๊ฐ ์์๊ธฐ ๋๋ฌธ์ NGINX ์ค์ ์ ๋ฌธ์ ์ฒ๋ผ ๋ณด์๋ค.
๐ค ์์ธ :
๐ ์ด ๋ฌธ์ ๋ฅผ ์ ํํ ์ดํดํ๊ธฐ ์ํด์๋ ssl ์ธ์ฆ์์ ๊ทธ ์ข ๋ฅ์ ๋ํด ์๊ณ ์์ด์ผ ํ๋ค.
- ssl ์ธ์ฆ์ ํต์ฌ์ ์ ๋ขฐ๊ธฐ๊ด(CA)์ผ๋ก๋ถํฐ ๋์งํธ ๋ฐฉ์์ผ๋ก ์๋ช
๋ฐ์ ์ธ์ฆ์๋ฅผ ๋ฐํ์ผ๋ก ํด๋น ์ฌ์ดํธ๊ฐ ์์ ํจ์ ์ธ์ฆ๋ฐ๋ ๊ฒ์ด๋ค.
- ์ธ์ฆ์๋ ๋๊ตฌ๋ ๋ง๋ค ์ ์๋๋ฐ ์น ๋ธ๋ผ์ฐ์ ์์๋ ๊ณต์ธ ์ธ์ฆ ๊ธฐ๊ด์ ๋ชฉ๋ก์ ํฌํจ๋์ด ์๋ ์กฐ์ง์์ ๋ฐ๊ธํ ์ธ์ฆ์๋ง์ ์ ๋ขฐํ๋ค.
- ๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ์๋ ์ ๋ขฐ๋ฐ์ง ๋ชปํ ์ฌ์ดํธ๋ผ๋ฉฐ ๊ฒฝ๊ณ ๋ฌธ๊ตฌ๋ฅผ ๋ด๋ณด๋ธ๋ค.
- ssl ์ธ์ฆ์๋ ๋ฃจํธ ์ธ์ฆ์, ์ฒด์ธ ์ธ์ฆ์, ์๋ฒ(๋๋ฉ์ธ) ์ธ์ฆ์๊ฐ ์๋ค.
- SSL ์ธ์ฆ์๋ฅผ ๋ฐ๊ธ๋ฐ์ผ๋ฉด ๊ธฐ๋ณธ์ ์ผ๋ก ๋ฃจํธ์ธ์ฆ์, ์ฒด์ธ์ธ์ฆ์, ์๋ฒ์ธ์ฆ์, ํค ์ด๋ ๊ฒ ๋ค ๊ฐ์ ํ์ผ์ด ํฌํจ๋์ด ์๋ค.
- ์น ๋ธ๋ผ์ฐ์ ๋ ๊ณต๊ณต ์ธ์ฆ ๊ธฐ๊ด์ ๋ฃจํธ ์ธ์ฆ์๋ฅผ ์ ๋ขฐํ๊ณ ์๊ธฐ ๋๋ฌธ์ ๋ฃจํธ ์ธ์ฆ์์ ์๋ฒ ์ธ์ฆ์๋ฅผ ์ฒด์ธ ์ธ์ฆ์๋ก ์ฐ๊ฒฐํ์ฌ ํด๋น ์๋ฒ ์ธ์ฆ์๊ฐ ๊ณต์ธ ์ธ์ฆ ๊ธฐ๊ด์ผ๋ก๋ถํฐ ๋ฐ๊ธ๋ ๊ฒ์์ ์ ๋ขฐํ ์ ์๋ค.
- ๋์ ๊ฒฝ์ฐ์๋ ์๋ฒ ์ธ์ฆ์ ํ๋๋ง nginx.conf์ ๋ฑ๋กํ๊ธฐ ๋๋ฌธ์ ์์ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ ๊ฒ์ด๋ค.
๐ค ํฌ๋กฌ ๋ธ๋ผ์ฐ์ ์ Postman์์๋ ๋ฌธ์ ์์ด ์๋ํ๋๋ฐ?
- ์ต์ ์น๋ธ๋ผ์ฐ์ ๋ฑ์๋ ๋ฃจํธ ์ธ์ฆ์ ์ธ์๋ ์ฒด์ธ ์ธ์ฆ์๊น์ง ๋ชฉ๋ก์ ๋ณด์ ํ๊ณ ์์ด ์๋ฒ ์ธ์ฆ์๋ง์ ์ค์ ํด๋ ์ ์์ด ๊ฐ๋ฅํ๋ค.
- ๋ก์ปฌ PC์ ํฌ๋กฌ ๋ธ๋ผ์ฐ์ ์ Postman์์ ๋ฌธ์ ์์ด ์ ์์ด ๊ฐ๋ฅํ๋ ์ด์ ๊ฐ ์ฌ๊ธฐ์ ์๋ค.
- ๊ด๋ จ ๋ธ๋ก๊ทธ๋ฅผ ์ฐพ์๋ณด๋ CENTOS์ ๊ฒฝ์ฐ 7.7๊น์ง๋ sectigo(์ธ์ฆ๊ธฐ๊ด) ๋ฃจํธ ์ธ์ฆ์๋ฅผ ์๋์ผ๋ก ์๋ฒ์ ๋ฑ๋ก์ ํด์ค์ผ ํ๋ ๋ฏํ๋ค.
- ํ์ฌ sectigo ์ธ์ฆ์๋ฅผ ์ฌ์ฉ ์ค์ด๋ค.
- ๊ทธ๋์ ์๋ฒ์์ curl ๋ช ๋ น์ด๋ก ์ ์์ ์๋ํ์ ๋๋ ์๋ฌ๊ฐ ๋ฐ์ํ ๊ฒ์ด๋ค.
๐ค ๊ทธ๋ผ ๊ธฐ์กด์ application.properties๋ก ssl ์ ์ฉ์ ํ์ ๋๋ ์ ๋ฌธ์ ๊ฐ ์์๋์ง?
- ์คํ๋ง๋ถํธ ์๋ฒ์ ๊ฒฝ์ฐ .pfx ํ์ผ๋ก ์ด๋ฏธ ํตํฉ๋ ์ธ์ฆ์๋ฅผ ์ฌ์ฉํ๊ณ ์์๊ธฐ ๋๋ฌธ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ง ์์๋ค.
- ๊ทธ๋ฐ๋ฐ ์ด .pfx๋ฅผ ๊ทธ๋๋ก nginx์ ssl_certificate์ ์ ์ฉํ๋ฉด nginx: [emerg] invalid number of arguments in "ssl_certificate" directive in ... ์ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.
- ๊ทธ๋์ ์๋ฒ ์ธ์ฆ์๋ฅผ ๋ฐ๋ก ์ฌ์ฉํ๋ค๊ฐ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ๊ฒ์ด๋ค.
๐ ํด๊ฒฐ :
https://www.comodossl.co.kr/certificate/ssl-installation-guides/Nginx.aspx
Nginx : ์ธ์ฆ์ ์ ์ฉ - HanbiroSSL
SSL ๋ณด์ ์๋ฒ ์ธ์ฆ ๊ฐ์ฅ ํฉ๋ฆฌ์ ์ธ ๊ฐ๊ฒฉ์ Sectigo SSL ์ธ์ฆ์ ํตํด ๊ท์ฌ์ ์น์๋ฒ์ ์ ์ํ๋ ํ์๋ค์ ๊ฐ์ธ ์ ๋ณด๋ฅผ ์์ ํ๊ฒ ๋ณดํธํด ์ฃผ์๊ธฐ ๋ฐ๋๋๋ค. --> ๋ณธ ๊ฐ์ด๋๋ ์ธ์ฆ์ ํ์ผ ์ค์ ์ ์ฐธ๊ณ ์
www.comodossl.co.kr
cat ๋๋ฉ์ธ.crt ์ฒด์ธ.crt. ๋ฃจํธ.crt > nginx_ssl
- ์ ๋งํฌ์ ๋์จ ํ์๋๋ก cat ๋ช ๋ น์ด๋ก ์ธ์ฆ์๋ฅผ ํฉ์ณ ์๋ก์ด nginx_ssl ํ์ผ์ ๋ง๋ค๊ณ ์ ์ฉํ๋ ๋ฌธ์ ์์ด ์๋ํ๋ค.
- bundle ํ์ผ์ด ๋ฐ๋ก ์กด์ฌํ์ฌ ์ฒด์ธ+๋ฃจํธ ํ๋๋ก ํฉ์น ๊ฒฝ์ฐ๋ ์์ผ๋ ๋ฐ๊ธ๋ฐ์ ์ธ์ฆ์ ์ฌ์ดํธ์์ ์ฐพ์๋ณด๋ ๊ฒ์ด ๋ณด๋ค ์ ํํ๊ฒ ์ ์ฉํ ์ ์์ ๊ฒ์ด๋ค.
๐ค ์๋ฌธ์ :
์์
์ฐธ๊ณ
https://velog.io/@gomil/Nginx-SSL-์ ์ฉ-With-Chain-์ธ์ฆ์
728x90