Apache Webserver HTTPS + DDNS
1. Apache2, Certbot 설치
sudo apt install apache2 certbot python3-certbot-apache
2. Apache2 설정
sudo a2enmod ssl
sudo cp /etc/apache2/sites-available/{default-ssl,gamu.kr}.conf
<VirtualHost *:443>
ServerName gamu.kr ## 추가
ServerAlias www.gamu.kr ## ServerAlias는 더 추가 가능
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
<FilesMatch "\.(?:cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
sudo a2ensite gamu.kr.conf
sudo systemctl restart apache2
3. Certbot 설정
sudo certbot --apache ## 실행후 질문에 선택사항 입력. !!Double Dash!!
sudo systemctl restart apache2
sudo systemctl status certbot.timer ## 갱신 작동 확인
다음과 같은 메세지 출력시에는
Unable to find corresponding HTTP vhost;
Unable to create one as intended addresses conflict;
Current configuration does not support automated redirection
이 방법으로 적용
certbot certonly --standalone -d gamu.kr,www.gamu.kr
4. DDNS 자동 갱신
/usr/lib/systemd/system/gamu.service 작성
[Unit]
Description=gamu.kr & www.gamu.kr DDNS(DnsZi) Renewal Service
[Service]
Type=oneshot
## DNSZi 사이트에서 코드 발행후 입력
ExecStart=$(type -p wget) -q -O - 'http://ddns.dnszi.com/set.html?user=<ddnzi-id>&auth=<dnszi-auth-key>&domain=gamu.kr&record='
/usr/lib/systemd/system/gamu.timer 작성
[Unit]
Description=Run DDNS(https://dnszi.com) Service Renewal twice daily
[Timer]
OnCalendar=*-*-* 00,12:00:00
RandomizedDelaySec=43200
Persistent=true
[Install]
WantedBy=timers.target
systemd 등록, 실행
sudo systemctl enable gamu.timer # 부팅시 타이머 실행 설정
sudo systemctl start gamu.timer # 타이머 실행
sudo systemctl status gamu # 등록한 타이머 상태 확인