아파치 https 구성

아파치 https 구성을 위한 mod ssl 모듈 설치 및 openssl 키구성 과정 예시 입니다.

※ CentOS 6.x 기준으로 작성 되었던 내용입니다. 그리고 아파치를 컴파일로 설치했을 경우 mod_ssl도 다시 컴파일로 설치를 진행해야 합니다.

  • mod_ssl, openssl 선설치
// 설치 여부 확인
# rpm -qa | grep -E "mod_ssl|openssl"

# yum install mod_ssl openssl -y
  • self-signed certificate 생성
// 개인키 생성
# openssl genrsa -out ca.key 1024

// CSR(Certificate Signing Request) 생성
# openssl req -new -key ca.key -out ca.csr
// 국가/주(도)/시/사명//domain(hostname)/// 영문으로 각 순서에 입력

// Self Signed Key 생성
# openssl x509 -req -days 3650 -in ca.csr -signkey ca.key -out ca.crt

// 생성키 복사 처리
# cp ca.crt /etc/pki/tls/certs/
# cp ca.key /etc/pki/tls/private/ca.key
# cp ca.csr /etc/pki/tls/private/ca.csr

※ selinux 인해 삭제시 복구
# restorecon -RvF /etc/pki
  • ssl용 config 수정
# /etc/httpd/conf.d/ssl.conf 수정
#경로 및 파일명 수정
SSLCertificateFile /etc/pki/tls/certs/ca.crt
SSLCertificateKeyFile /etc/pki/tls/private/ca.key
  • httpd config 수정
# /etc/httpd/conf/httpd.conf에 추가
NameVirtualHost *:443 #2.4버전에서는 삭제
<VirtualHost *:443>
  SSLEngine on
  SSLCertificateFile /etc/pki/tls/certs/ca.crt
  SSLCertificateKeyFile /etc/pki/tls/private/ca.key
  ServerAdmin hello.co.kr #인증서 생성 과정에서 설정해준 사용자명 혹은 서버 호스트명은 이곳에 똑같이 적어준다
  DocumentRoot /var/www/html
  ServerName hello.co.kr #인증서 생성 과정에서 설정해준 사용자명 혹은 서버 호스트명은 이곳에 똑같이 적어준다
  ErrorLog logs/ssl_starkapin_com_error_log
  CustomLog logs/ssl_starkapin_com_error_log common
</VirtualHost>

# 페이지 리다이렉트
# mod_rewirte 모듈 활성화 필요
# /etc/httpd/conf/httpd.conf 수정
<VirtualHost *:80>
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
</VirtualHost>
  • 서비스 재시작
// CentOS 6.x
# service httpd restart

// CentOS 7.x
#systemctl restart httpd
  • 정상 구동 확인
// 80, 443포트 리슨 확인
# netstat -ntlp

// 브라우저 통해 실제 http 접속후 https로 리다이렉션 여부 확인

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

이 사이트는 Akismet을 사용하여 스팸을 줄입니다. 댓글 데이터가 어떻게 처리되는지 알아보세요.