Sever/CentOS 6.10

[Linux] CentOS 6.10 - 15. Apache SSL 설정하기

곰시기 2020. 12. 3. 17:44
설정 전에...
  • SSL이란?
    1. 인터넷 상에서 데이터를 안전하게 전송하기 위한 인터넷 암호화 통신 프로토콜을 말하며, CA( Certificate Authority )라고 불리는 서드 파티로부터 서버와 클라이언트의 인증을 하는데 사용된다.
      좀 더 자세한 사항은 여기에 잘 정리되어있다.
  • 모듈 설치
    1. openssl 설치 확인
      [root@localhost ~]# yum list installed | grep openssl
      openssl.x86_64        1.0.1e-58.el6_10 @updates // 이와 같은 항목이 뜨지 않는다면
      openssl-devel.x86_64  1.0.1e-58.el6_10 @updates // 설치가 안된 것, 아래와 같이 설치
      [root@localhost ~]# yum -y install openssl
    2. apache mod_ssl 모듈 적용
      [root@localhost ~]# httpd -D DUMP_MODULES // httpd는 apachectl를 Alias설정한 것
      1. Apach 설치를 진행할 때 DSO방식( --enable-shared 옵션의 값을 all 또는 max )으로 설치를 진행 하였다면 Apache를 재컴파일 할 필요 없이 모듈만 추가시키면 된다. 아래는 모듈 추가방법이다.
      [root@localhost ~]# cd {Apache 압축을 푼 디렉터리}/modules/ssl 
      [root@localhost ssl]# {Apache 설치한 디렉터리}/bin/apxs -aic mod_ssl.c
      [root@localhost ssl]# vi {Apache 설치한 디렉터리}/conf/httpd.conf
      // LoadModule에 ssl모듈이 등록되어 있는지 확인
      [root@localhost ssl]# httpd restart
      ~~~ssl_module is built-in and can't be loaded
      // 위와 같은 에러 발생은 Apache를 컴파일 할 때
      // 이미 모듈을 적재 하였다는 것이므로 httpd.conf에서
      // 위 사진의 내용 부분을 지우거나 주석처리 후
      // {Apache 설치한 디렉터리}/modules/ 에서 mod_ssl.so파일 삭제
  • 방화벽 설정
    [root@localhost ~]# iptables -I INPUT 1 -p tcp --dport 443 -j ACCEPT
    [root@localhost ~]# service iptables save
    [root@localhost ~]# service iptables restart
  • ssl 디렉터리 생성 // ssl-key등의 관리를 위해 특정 디렉터리를 생성
    [root@localhost ~]# cd /usr/apache/conf/
    [root@localhost usr]# mkdir -m 755 ssl
    

 

SSL 설정( 사설 인증서 )
  1. 개인 키 생성
    [root@localhost ssl]# cd /usr/apache/conf/ssl/
    [root@localhost ssl]# openssl genrsa -out testServer.key 2048
    Generating RSA private key, 2048 bit long modulus
    .........+++
    .................+++
    e is 65537 (0x10001)
    1. openssl 명령어를 이용하여 개인키를 생성
  2. csr파일 생성
    [root@localhost ssl]# openssl req -new -key testServer.key > testServer.csr
    You are about to be asked to enter information that will be incorporated
    into your certificate request.
    What you are about to enter is what is called a Distinguished Name or a DN.
    There are quite a few fields but you can leave some blank
    For some fields there will be a default value,
    If you enter '.', the field will be left blank.
    -----
    Country Name (2 letter code) [XX]:KR                                    // 국가명
    State or Province Name (full name) []:Daegu                             // 도 or 시
    Locality Name (eg, city) [Default City]:Dong-gu                         // 시 or 구
    Organization Name (eg, company) [Default Company Ltd]:test              // 회사명
    Organizational Unit Name (eg, section) []:devel                         // 부서명
    Common Name (eg, your name or your server's hostname) []:testServer.com // 서버 호스팅 이름
    Email Address []:blabla@bla.com                                         // 관리자 메일
    
    Please enter the following 'extra' attributes
    to be sent with your certificate request
    A challenge password []:                                                // Enter
    An optional company name []:                                            // Enter
    1. 위에서 생성한 개인키를 이용하여 csr파일 생성
    2. csr? 회사의 정보를 암호화하여 인증기관으로 보내 인증서를 발급받게 하는 일종의 신청서
  3. 인증서 생성
    [root@localhost ssl]# openssl x509 -req -days 365 -in testServer.csr -signkey testServer.key -out testServer.crt
    Signature ok
    subject=/C=KR/ST=Daegu/L=Dong-gu/O=test/OU=devel/CN=testServer.com/emailAddress=blabla@bla.com
    Getting Private key
  4. 키 등록
    [root@localhost ssl]# vi {apache 설치 경로}/conf/extra/httpd-vhosts.conf
    SSLCertificateFile "{apache 설치 경로}/conf/ssl/testServer.crt"
    SSLCertificateKeyFile "{apache 설치 경로}/conf/ssl/testServer.key"
    # 위 두가지를 생성한 파일로 교체
  5. Apache 재실행
    [root@localhost ssl]# httpd restart