Skip to main content

4-11. SSL

About 2 minJavaSpringAWScrashcoursejavajdkjdk8streamspringspringframeworkspringbootawsaws-ec2

4-11. SSL ๊ด€๋ จ


4-11. SSL

์ ํ”„ ํˆฌ ์Šคํ”„๋ง๋ถ€ํŠธ - WikiDocs

์ด์ œ ๋ธŒ๋ผ์šฐ์ €์—์„œ ๊ณ ์ • IP ๋Œ€์‹  ๋„๋ฉ”์ธ์„ ์ž…๋ ฅํ•˜์—ฌ ์„œ๋ฒ„์— ์ ‘์†ํ• ์ˆ˜ ์žˆ๊ฒŒ ๋˜์—ˆ๋‹ค.

ํ•˜์ง€๋งŒ ๋ธŒ๋ผ์šฐ์ €์˜ ์ฃผ์†Œ์ฐฝ์„ ๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด "์ฃผ์˜ ์š”ํ•จ" ์ด๋ผ๋Š” ๊ฒฝ๊ณ  ๋ฉ”์‹œ์ง€๊ฐ€ ํ‘œ์‹œ๋œ๋‹ค.
ํ•˜์ง€๋งŒ ๋ธŒ๋ผ์šฐ์ €์˜ ์ฃผ์†Œ์ฐฝ์„ ๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด "์ฃผ์˜ ์š”ํ•จ" ์ด๋ผ๋Š” ๊ฒฝ๊ณ  ๋ฉ”์‹œ์ง€๊ฐ€ ํ‘œ์‹œ๋œ๋‹ค.

์ด๋Ÿฌํ•œ ๊ฒฝ๊ณ ๋ฉ”์‹œ์ง€๊ฐ€ ๋ณด์ด๋Š” ์ด์œ ๋Š” https://pybo.kr ์ด ์•„๋‹Œ http://pybo.kr ์ฒ˜๋Ÿผ https๊ฐ€ ์•„๋‹Œ http ํ”„๋กœํ† ์ฝœ์„ ์‚ฌ์šฉํ–ˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ๋ธŒ๋ผ์šฐ์ €๋Š” HTTPS ๊ฐ€ ์•„๋‹Œ HTTP ์‚ฌ์šฉ์‹œ ํ•ญ์ƒ ์ด๋Ÿฌํ•œ ๊ฒฝ๊ณ  ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด์—ฌ์ค€๋‹ค.

http์— ๋ณด์•ˆ๊ธฐ๋Šฅ(SSL)์„ ๋”ํ•œ ๊ฒƒ์ด https ํ”„๋กœํ† ์ฝœ์ด๋‹ค.


HTTPS๊ฐ€ ํ•„์š”ํ•œ ์ด์œ 

HTTPS ๊ฐ€ ์•„๋‹Œ HTTP ํ”„๋กœํ† ์ฝœ์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ธŒ๋ผ์šฐ์ €(ํด๋ผ์ด์–ธํŠธ)์™€ SBB ์„œ๋น„์Šค(์„œ๋ฒ„) ์‚ฌ์ด์— ์ฃผ๊ณ  ๋ฐ›๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ์•”ํ˜ธํ™” ๋˜์ง€ ์•Š๋Š”๋‹ค. ํด๋ผ์ด์–ธํŠธ์™€ ์„œ๋ฒ„๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ์ฃผ๊ณ  ๋ฐ›๋Š” ๋„คํŠธ์›Œํฌ ๊ฒฝ๋กœ๋Š” ๋งค์šฐ ๋ณต์žกํ•œ๋ฐ ์ด ๊ณผ์ •์—์„œ ๋ˆ„๊ตฐ๊ฐ€(ํ•ด์ปค)๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ํ›”์ณ๋ณด๋Š” ์ผ์€ ์–ด๋ ต์ง€ ์•Š๋‹ค. ๋”ฐ๋ผ์„œ ๋„คํŠธ์›Œํฌ ๊ตฌ๊ฐ„์—์„œ ์ฃผ๊ณ ๋ฐ›๋Š” ๋ฐ์ดํ„ฐ๋Š” ๋ฐ˜๋“œ์‹œ ์•”ํ˜ธํ™” ํ•˜์—ฌ ๋ฐ์ดํ„ฐ๊ฐ€ ๋…ธ์ถœ๋˜๋”๋ผ๋„ ๋ฌด์Šจ ๋‚ด์šฉ์ธ์ง€ ์•Œ์ˆ˜ ์—†๊ฒŒ ํ•ด์•ผ ํ•œ๋‹ค.

์ด๋Ÿฌํ•œ ์—ญํ• ์„ ํ•˜๋Š” ๊ฒƒ์ด ๋ฐ”๋กœ HTTP์— SSL(Secured Socket Layer) ๊ธฐ๋Šฅ์„ ๋”ํ•œ HTTPS ํ”„๋กœํ† ์ฝœ์ด๋‹ค. ์šฐ๋ฆฌ๊ฐ€ ๋งŒ๋“  SBB ์„œ๋น„์Šค์— HTTPS ํ”„๋กœํ† ์ฝœ์„ ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” SSL ์ธ์ฆ์„œ๊ฐ€ ํ•„์š”ํ•˜๋‹ค. SSL ์ธ์ฆ์„œ๋ฅผ ๋ฐœ๊ธ‰๋ฐ›์•„ Nginx์— ์ ์šฉํ•˜๋ฉด HTTPS ํ”„๋กœํ† ์ฝœ๋กœ ์„œ๋น„์Šค๋ฅผ ํ• ์ˆ˜ ์žˆ๋‹ค.

๐Ÿ“š์ฐธ๊ณ  : SSLopen in new window


SSL ์ธ์ฆ์„œ ๋ฐœ๊ธ‰

SSL ์ธ์ฆ์„œ๋Š” ์ธ์ฆ ๊ธฐ๊ด€์—์„œ ์ธ์ฆํ•˜๋Š” ์ธ์ฆ์„œ๋ฅผ ๋ฐœ๊ธ‰ ๋ฐ›์•„์•ผ ํ•œ๋‹ค. ์™œ๋ƒํ•˜๋ฉด ๋ธŒ๋ผ์šฐ์ €์— ์ด๋ฏธ SSL ์ธ์ฆ์„ ์œ„ํ•œ ์ธ์ฆ ๊ธฐ๊ด€๋“ค์ด ๋“ฑ๋ก๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

์ธ์ฆ ๊ธฐ๊ด€์œผ๋กœ ๋“ฑ๋ก๋˜์ง€ ์•Š์€ ๊ธฐ๊ด€์—์„œ ์ธ์ฆํ•œ ์ธ์ฆ์„œ๋Š” ์ธ์ •๋˜์ง€ ์•Š๋Š”๋‹ค.

๋Œ€ํ‘œ์ ์ธ ์ธ์ฆ ๊ธฐ๊ด€์œผ๋กœ๋Š” Comodo, Thawte, GeoTrust, DigiCert ๋“ฑ์ด ์žˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ธ์ฆ ๊ธฐ๊ด€์—์„œ ์ธ์ฆ์„œ๋ฅผ ๋ฐœ๊ธ‰ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค. ํ•˜์ง€๋งŒ ์ด๋Ÿฌํ•œ ์ธ์ฆ ๊ธฐ๊ด€์˜ SSL ์ธ์ฆ์„œ๋Š” ์œ ๋ฃŒ์ด๋‹ค. (์ธ์ฆ์„œ์˜ ๊ฐ€๊ฒฉ์€ ์ธ์ฆ ๊ธฐ๊ด€๋ณ„๋กœ ๋‹ค๋ฅด๋‹ค.)

์ด ์ฑ…์—์„œ๋Š” ๋ฌด๋ฃŒ๋กœ SSL ์ธ์ฆ์„œ๋ฅผ ๋ฐœ๊ธ‰ํ•ด ์ฃผ๋Š” Let's Encrypt ์„œ๋น„์Šค๋ฅผ ์‚ฌ์šฉํ•ด ๋ณด์ž.


Let's Encrypt ์ธ์ฆ์„œ ์„ค์น˜

์„œ๋ฒ„์— ์ ‘์†ํ•œํ›„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด certbot์„ ์„ค์น˜ํ•˜์ž.

sudo apt install certbot
sudo apt install python3-certbot-nginx

๊ทธ๋ฆฌ๊ณ  ๋‹ค์Œ์ฒ˜๋Ÿผ Nginx ์›น์„œ๋ฒ„์— ์‚ฌ์šฉํ•  Let's Encrypt์˜ ์ธ์ฆ์„œ๋ฅผ ๋ฐœ๊ธ‰ํ•˜์ž.

sudo certbot certonly --nginx
#
# Saving debug log to /var/log/letsencrypt/letsencrypt.log
# Plugins selected: Authenticator nginx, Installer nginx
# Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): 
pahkey@gmail.com
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Please read the Terms of Service at
# https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
# agree in order to register with the ACME server at
# https://acme-v02.api.letsencrypt.org/directory
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# (A)gree/(C)ancel: 
a
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Would you be willing to share your email address with the Electronic Frontier
# Foundation, a founding partner of the Let's Encrypt project and the non-profit
# organization that develops Certbot? We'd like to send you email about our work
# encrypting the web, EFF news, campaigns, and ways to support digital freedom.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# (Y)es/(N)o: 
y
# No names were found in your configuration files. Please enter in your domain name(s) (comma and/or space separated)  
# (Enter 'c' to cancel): 
pybo.kr
#
# Obtaining a new certificate
# Performing the following challenges:
# http-01 challenge for pybo.kr
# Using default address 80 for authentication.
# Waiting for verification...
#
# (... ์ƒ๋žต ...)
ย 




ย 








ย 











ย 








์ˆœ์„œ๋Œ€๋กœ ์ด๋ฉ”์ผ์ฃผ์†Œ, ๋™์˜ํ•จ(a), ์˜ˆ(y), ๋„๋ฉ”์ธ๋ช…(์˜ˆ:pybo.kr)์„ ์ž…๋ ฅํ•˜์ž. ๊ทธ๋Ÿฌ๋ฉด ๋‹ค์Œ ์œ„์น˜์— ์ธ์ฆ์„œ๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค.

  • ./etc/letsencrypt/live/pybo.kr/fullchain.pem
  • ./etc/letsencrypt/live/pybo.kr/privkey.pem

๋…ธ๋ž€์ƒ‰์œผ๋กœ ๋งˆํ‚นํ•œ pybo.kr์€ ์—ฌ๋Ÿฌ๋ถ„์˜ ๋„๋ฉ”์ธ๋ช…์œผ๋กœ ๋Œ€์ฒดํ•ด์•ผ ํ•จ์— ์ฃผ์˜ํ•˜์ž.


Nginx ์„ค์ •

์ด์ œ ์„ค์น˜ํ•œ SSL ์ธ์ฆ์„œ๋ฅผ Nginx์— ์ ์šฉํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์ด sbb ํŒŒ์ผ์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜์ •ํ•˜์ž.

ํŒŒ์ผ๋ช…: /etc/nginx/sites-available/sbb

server {
        listen 80;
        server_name pybo.kr;
        rewrite        ^ https://$server_name$request_uri? permanent;
}

server {
        listen 443 ssl;
        server_name pybo.kr;

        ssl_certificate /etc/letsencrypt/live/pybo.kr/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/pybo.kr/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot

        location / {
                proxy_pass http://localhost:8080;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
        }
}
ย 
ย 
ย 
ย 



ย 


ย 
ย 
ย 








HTTP ์š”์ฒญ(80๋ฒˆ ํฌํŠธ)์€ HTTPS(443๋ฒˆ ํฌํŠธ)๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ํ•˜๋„๋ก ์„ค์ •ํ–ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์„ค์น˜ํ•œ SSL ์ธ์ฆ์„œ๋ฅผ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•ด SSL ๊ด€๋ จ ์„ค์ •๋“ค์„ ์ ์šฉํ–ˆ๋‹ค.

์œ„ ์„ค์ •์—์„œ ์‚ฌ์šฉํ•œ ๋„๋ฉ”์ธ๋ช… pybo.kr์„ ์—ฌ๋Ÿฌ๋ถ„์˜ ๋„๋ฉ”์ธ๋ช…์œผ๋กœ ๋ฐ”๊พธ์–ด์•ผ ํ•จ์— ์ฃผ์˜ํ•˜์ž.

์ด์™€ ๊ฐ™์ด Nginx ์„ค์ •์„ ๋ฐ”๊พผํ›„์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด Nginx๋ฅผ ์žฌ์‹œ์ž‘ํ•˜์ž.

sudo systemctl restart nginx.service

SSL ๋ฐฉํ™”๋ฒฝ ์„ค์ •

Nginx์— SSL์„ ์ ์šฉํ•˜๋ฉด SSL์˜ ํฌํŠธ์ธ 443๋ฒˆ ํฌํŠธ์˜ ๋ฐฉํ™”๋ฒฝ ํ•ด์ œ๊ฐ€ ํ•„์š”ํ•˜๋‹ค. ๋‹ค์Œ์„ ์ฐธ๊ณ ํ•˜์—ฌ 443๋ฒˆ ํฌํŠธ์˜ ๋ฐฉํ™”๋ฒฝ์„ ํ•ด์ œํ•˜์ž.

IPv4 ๋ฐฉํ™”๋ฒฝ
IPv4 ๋ฐฉํ™”๋ฒฝ

HTTPS ํ™•์ธ

์ด์ œ ๋ธŒ๋ผ์šฐ์ €์—์„œ http://pybo.kr ๋Œ€์‹  https://pybo.kr๋กœ ์ ‘์†ํ• ์ˆ˜ ์žˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ด์ „์— ํ‘œ์‹œ๋˜๋˜ "์ฃผ์˜์š”ํ•จ" ๊ฒฝ๊ณ ๋ฉ”์‹œ์ง€๋„ ์‚ฌ๋ผ์ง€๊ณ  ์ธ์ฆ์„ ์˜๋ฏธํ•˜๋Š” ์ž๋ฌผ์‡  ๋ชจ์–‘์˜ ์•„์ด์ฝ˜๋„ ํ‘œ์‹œ๋  ๊ฒƒ์ด๋‹ค.


์ด์ฐฌํฌ (MarkiiimarK)
Never Stop Learning.