https – SSL 보안연결 사이트로 전환.

일반적으로 apache나 nginx를 통해 웹서버를 올리면 http 즉 암호화되지 않는 사이트가 실행된다.
단순한 페이지라면 크게 상관이 없겠으나 정보를 주고 받는 웹사이트라면 암호화된 연결을 사용해,
중간에 제3자가 패킷을 탈취해도 그 내용을 볼 수가 없다.

이것은 우리가 현재 인터넷을 사용하기 위해 사용하는 네트워크의 통신방식과 관련이 있다.
기본적으로 PC의 통신 방법은 같은 네트워크 내에 있는 모두에게 소리치는 방식이다.
그럼 필요한 사람만 귀를 귀울이는 방식이다. 악의적으로 엿들을려는 시도를 차단 할 수가 없다.
그래서 둘 사이의 암호화를 하며 인터넷에서는 https로 시작하는 주소이며, 무선에서는 SSID 연결시
연결 암호를 넣는 것이다.
웹을 제외한 나머지는 app단에서 종단암호화를 한다. 스마트폰 초기에 이런 보안조치가 없어서 수 많은
개인 해킹사고가 일어났다. 왜 밖에서 무선인터넷을 사용하다가 핸드폰이 해킹당한 사례를 한 번쯤 들어봤을 듯 하다.

내가 운영하는 웹사이트 암호화하기 위해서는 인증서 라는 것이 필요하다. 그런데 이 인증서의 가격이 웹사이트 도메인에 붙일려면 1년에 몇 만원 수준의 유료서비스이다.
좀 더 범용적으로 VPN연결, AD인증 등 여러가지에 사용할려면 가격이 더 올라가는 구조이다.
개인적으로 도메인도 제일 싼거로 1년마다 메뚜기 짓을 하는 입장에서 비효율적이다.

사람사는 것이 다 방법이 있듯이 개인에게 90일짜리 무료인증서를 제공하는 기관이 있다.
물론 90일마다 갱신하는 것도 가능하다. (Let’s Encrypt : https://letsencrypt.org/ko/)
설치방법도 너무 쉬워서 권장한다.


1. certbot 설치

# apt install certbot python3-certbot-apache
우분투에서는 간단하게 certbot, python3-certbot-apache 를 설치하면 가능.
웹사이트에서 별도로 인증서 발급하고 웹서버에 등록도 가능하지만, 웹서버에서 실행시 자동으로 ssl용 conf 까지 생성 및 발급된 인증서 다운로드됨.
nginx 사용자는 “python3-certbot-nginx” 로 plugin으로 설치 변경.

# apt install certbot python3-certbot-apache
Reading package lists… Done
Building dependency tree
Reading state information… Done
Suggested packages:
python3-certbot-nginx python-certbot-doc python-certbot-apache-doc
The following NEW packages will be installed:
certbot python3-certbot-apache
0 upgraded, 2 newly installed, 0 to remove and 147 not upgraded.
Need to get 88.1 kB of archives.
After this operation, 481 kB of additional disk space will be used.
Get:1 http://ap-seoul-1-ad-1.clouds.archive.ubuntu.com/ubuntu focal-updates/universe amd64 certbot all 0.40.0-1ubuntu0.1 [17.9 kB]
Get:2 http://ap-seoul-1-ad-1.clouds.archive.ubuntu.com/ubuntu focal/universe amd64 python3-certbot-apache all 0.39.0-1 [70.2 kB]
Fetched 88.1 kB in 2s (44.2 kB/s)
Selecting previously unselected package certbot.
(Reading database … 226049 files and directories currently installed.)
Preparing to unpack …/certbot_0.40.0-1ubuntu0.1_all.deb …
Unpacking certbot (0.40.0-1ubuntu0.1) …
Selecting previously unselected package python3-certbot-apache.
Preparing to unpack …/python3-certbot-apache_0.39.0-1_all.deb …
Unpacking python3-certbot-apache (0.39.0-1) …
Setting up certbot (0.40.0-1ubuntu0.1) …
Setting up python3-certbot-apache (0.39.0-1) …
Processing triggers for man-db (2.9.1-1) …
… (생략)

2. certbot 인증서 등록

# certbot –apache
apache plugin을 이용하여 인증서 발급 및 SSL config 생성.

– 사용자 이메일 확인 / 입력
Enter email address (used for urgent renewal and security notices) (Enter ‘c’ to
cancel): email@iwgh.my
– 약관동의
Please read the Terms of Service at …
You must agree in order to register with the ACME server at…
(A)gree/(C)ancel: a
– 이메일 소식 구독 확인 (no 해도 진행가능)
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: n
– https 서비스를 사용할 웹서버 주소 선택
Which names would you like to activate HTTPS for?
1: (website address)
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter ‘c’ to cancel): 1
– 현재 apache 설정 확인하여 SSL vhost config 파일 생성
이후 https로 자동 redirect 선택.
Created an SSL vhost at /etc/apache2/sites-available/000-default-le-ssl.conf
…(생략)
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
1: No redirect – Make no further changes to the webserver configuration.
2: Redirect – Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you’re confident your site works on HTTPS. You can undo this
change by editing your web server’s configuration.
Select the appropriate number [1-2] then [enter] (press ‘c’ to cancel): 2
Redirecting vhost in /etc/apache2/sites-enabled/000-default.conf to ssl vhost in /etc/apache2/sites-available/000-default-le-ssl.conf

3. apache2 웹서버에 등록 및 재시작

sites-enable 에 등록까지 자동으로 되므로 apache SSL 모듈 enable, 재시작, 방화벽 open 필요.
# a2enmod ssl
# iptables -I INPUT 6 -m state –state NEW -p tcp –dport 443 -j ACCEPT
http로 접속시 https로 리다이렉션 및 정상 작동확인

4. 정상연결 검증

SSL 연결 상태 및 config확인
https://www.ssllabs.com/ssltest/analyze.html?d=MYURL

인증서는 기본적으로 90일 짜리로 발급되며 “certbot certificates” 명령어로 인증서 상태 확인 가능.
certbot renew 명령어를 통해 갱신가능.