회사/과제

Apache SSL 인증서

H E E 2022. 1. 12. 13:39
728x90

진행OS

KT Cloud 사용

 

준비물

 1. httpd (Apache)

 2. 서버와 연결되어 있는 도메인

 


📌 Apache SSL

 

1. mod_ssl / openssl 설치

yum install mod_ssl openssl

# 깔려 있을 때 결과
Nothing to do

 

2. ssl 파일들을 보관할 디렉토리 생성

# 파일생성
mkdir /etc/httpd/ssl

# 경로로 이동
cd /etc/httpd/ssl

 

3. 개인키 발급과 CSR, 자가 서명 인증서 생성

 

- Public Key 생성

# CA인증서 생성 개인키 생성
# openssl genrsa -out [파일명].key 2048
openssl genrsa -out ssltest.key 2048

 

- CSR (Certificate Signing Request) 생성

구분 예시
Country Name (국가 코드) KR
State or Province Name (시/도의 전체 이름) Gyeonggi-do
Locality Name (시/군/구 등의 이름) Bundang-gu
Organization (회사 이름) A회사
Organization Unit (부서명) Server
Common Name (SSL 인증서를 설치할 서버의 Full Domain) www.도메인.com
Email Address (이메일) email@exam.com
# 인증서 서명 요청(CSR) 생성
# openssl req -new -key [위에서 지정한 key파일명].key -out [파일명].csr
openssl req -new -key ssltest.key -out ssltest.csr

 

- CRT 인증서 생성

# 자가 서명 인증서를 생성
# 개인키와 CSR을 사용해서 인증서에 서명
# openssl x509 -req -days [기간] -in [csr파일명].csr -signkey [키파일명].key -out [지정할 crt파일명].crt
openssl x509 -req -days 365 -in ssltest.csr -signkey ssltest.key -out ssltest.crt

 


📌 httpd 수정

# 수정 위치
vi /etc/httpd/conf/httpd.conf

# ServerName 변경
# 변경 전
ServerName 14.63.173.12:80
# 변경 후
ServerName [도메인]:80

# LoadModule 추가
LoadModule ssl_module modules/mod_ssl.so

# 저장 후 종료
esc
:wq

 


📌 https:// 로 접속시 보여줄 index.html 파일 생성

 

1. 디렉토리 생성

mkdir /home/ssltest

 

2. 파일 생성

# index.html 생성
vi /home/ssltest/index.html

# 생성 후 아무 내용이나 입력
SSL Test!!

# 저장 후 종료
esc
:wq

 


📌 vhost.conf 수정

# 없으면 만들어야 한다.
# 혹시 모르니 vhost 설정시 80 포트도 설정하기
# 수정 위치
vi /etc/httpd/conf/vhost.conf

# 추가
<VirtualHost [도메인]:443>
 DocumentRoot /home/ssltest  # 보여줄 index.html의 위치
 ServerName [도메인]
 SSLEngine on
 SSLCertificateFile /etc/letsencrypt/live/[도메인]/cert.pem
 SSLCertificateKeyFile /etc/letsencrypt/live/[도메인]/privkey.pem
 SSLCertificateChainFile /etc/letsencrypt/live/[도메인]/chain.pem
</VirtualHost>

 


📌 ssl.conf 수정

# 수정 위치
vi /etc/httpd/conf.d/ssl.conf

# 수정
# 변경 전
<VirtualHost _default_:443>
# 변경 후
<VirtualHost *:443>

# 주석 해제
DocumentRoot "/var/www/html"
# 주석 해제 후 아래와 같이 수정
DocumentRoot "/home/ssltest"

# 주석 해제
ServerName www.example.com:443
# 주석 해제 후 아래와 같이 수정
ServerName [도메인]:443

# 주석 처리
SSLCertificateFile /etc/httpd/ssl/localhost.crt

# 추가
SSLCertificateFile /etc/httpd/ssl/ssltest.crt
SSLCertificateKeyFile /etc/httpd/ssl/ssltest.key

# 저장 후 종료
esc
:wq

 


📌 도메인 인증서 발급

 

# 방법 1 - webroot
# 접근가능경로 : .well-known이 있는 경로
certbot certonly --webroot -w [접근 가능 경로] -d [도메인]


# 방법 2 - standalone
certbot --authenticator standalone --installer apache -d [도메인] --pre-hook "systemctl stop httpd" --post-hook "systemctl start httpd"

# 방법 3 - 웹서버
# 80포트와 443포트 오픈
yum install python-certbot-apache
certbot --apache

# 자동 갱신
certbot renew

 


📌 https:// 로 접속시 403 에러

 

1. 권한 설정

chmod -R 755 /home/ssltest

 


📌  확인

 

 

728x90
반응형