서버에서 아이피 기반으로 보안 ssl을 사용할때가 가끔 있다
보안 SSL 아이피 기반으로 발급 받는 방법1. 기존 letcrypt로는 불가
2. lego 다운로드 및 설치
|
1 2 3 4 5 6 7 8 |
[root@xinet ~]# curl -L -o lego.tar.gz https://github.com/go-acme/lego/releases/latest/download/lego_v4.31.0_linux_amd64.tar.gz [root@xinet ~]# tar xvfz lego.tar.gz [root@xinet ~]# sudo install -m 0755 lego /usr/local/bin/lego [root@xinet ~]# lego --version lego version 4.31.0 linux/amd64 |
3. lego 명령어로 ip 인증서 발급
|
1 |
[root@xinet ~]# /usr/local/bin/lego --email="admin@xinet.kr" --accept-tos --path /etc/lego --disable-cn --http --http.webroot /free/home/xinet/html/ --domains "218.145.31.50" run --profile shortlived |
4. 파일 확인 및 pem 인증서 통합
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@xinet ~]# ls -l /etc/lego/certificates/ 합계 28 -rw------- 1 root root 4653 1월 19 14:31 218.145.31.50.crt -rw------- 1 root root 3453 1월 19 14:31 218.145.31.50.issuer.crt -rw------- 1 root root 234 1월 19 14:31 218.145.31.50.json -rw------- 1 root root 227 1월 19 14:31 218.145.31.50.key ### 인증서 통합 [root@xinet ~]# cd /etc/lego/certificates [root@xinet certificates]# cat 218.145.31.50.crt 218.145.31.50.issuer.crt > 218.145.31.50.fullchain.pem [root@xinet certificates]# chmod 600 218.145.31.50.* |
5. 웹서버에 등록 (nginx기준)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
server { listen 443 ssl http2; server_name 218.145.31.50; ssl_certificate /etc/lego/certificates/218.145.31.50.fullchain.pem; ssl_certificate_key /etc/lego/certificates/218.145.31.50.key; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; # (선택) HSTS – IP 기반이라면 보통 비활성 권장 # add_header Strict-Transport-Security "max-age=63072000" always; root /free/home/xinet/html; index index.html index.php; location / { try_files $uri $uri/ =404; } } |
자동으로 갱신되게 구성 crontab에 등록
|
1 |
[root@xinet certificates]# crontab -e |
|
1 |
0 3 * * * /usr/local/bin/lego --path /etc/lego --email admin@xinet.kr --accept-tos --disable-cn --http --http.webroot /free/home/xinet/html --domains 218.145.31.50 renew --profile shortlived --days 2 && /usr/bin/systemctl reload nginx |
cron 재시작
|
1 |
[root@xinet certificates]# systemctl restart crond |
