카테고리 없음

Apache2 에서 SSL 적용하기

랩퍼우26 2019. 1. 8. 23:11
728x90

Apache2 에서 SSL 적용하기 (apache2 에서는 기본으로 mod_ssl 이 설치되어 있다)

 

1. Openssl 설치 확인

find / -name openssl

 

없으면 설치

 

2. mod_ssl 모듈 설치 확인
statically linking module 로 설치된 mod_ssl 모듈확인
[root@web1 root]# $APACHE/bin/httpd -l
Compiled-in modules:
 ...
 mod_ssl.c
 ...
[root@web1 root]#

웹서버에 설치된 모듈중에 mod_ssl.c 을 확인합니다.

 DSO module 로 설치된 mod_ssl 모듈확인
[root@web1 root]# $APACHE/bin/httpd -l
Compiled-in modules:
 ...
 mod_so.c
 ...
[root@web1 root]# ls $APACHE/module
(1.3.29 이전 버전은 $APACHE/libexec 확인)
mod_ssl.so ...
[root@web1 root]#
 

없으면 설치

 

3. 개인키(비밀키) 생성

[root@web1 root]# cd $SSL_KEY_STORE
[root@web1 ssl]# openssl genrsa -des3 -out ssl_test.key 2048
Generating RSA private key, 2048 bit long modulus
.............++++++
...++++++
e is 65537 (0x10001)
Enter pass phrase for ssl2007.key: ******
Verifying - Enter pass phrase for ssl2007.key: ******
[root@web1 ssl]#
 

4. 개인키 확인

[root@web1 ssl]# openssl rsa -noout -text -in ssl_test.key
Enter pass phrase for ssl.key: ******
Private-Key: (2048 bit)
modulus:
    00:da:bf:f3:39:d7:c6:1f:bd:6f:a7:b8:aa:67:f2:
...
coefficient:
    6b:26:51:9e:fb:77:cf:7e:d4:2a:a6:d2:7f:21:fa:
    42:e4:7c:54:2e:5e:e9:fb:03:a6:25:d0:6a:fc:e9:
    e1:1b:45:82:61:c0:35:a9:50:25:0a:75:2a:f8:cc:
    87:10:30:9d:bd:36:8e:4b:f6:55:0d:08:30:e8:55:
    e4:00:3b:ec
[root@web1 ssl]#

 

5. CSR 생성

[root@web1 ssl]# openssl req -new -key ssl2007.key -out ssl_test.csr
Enter pass phrase for ssl.key: ******
...
Country Name (2 letter code) [KR]:kr
State or Province Name (full name) [Berkshire]:Seoul
Locality Name (eg, city) [Newbury]:Songpa
Organization Name (eg, company) [My Company Ltd]:Dotname Korea
Organizational Unit Name (eg, section) []:Digital Certificate Team
Common Name (eg, your name or your server's hostname) []:www.도메인명.co.kr
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: ******
An optional company name []:회사명
[root@web1 ssl]#

 

Country Name (국가코드) : KR
State or Province Name (시/도) : Seoul
Locality Name (구/군) : Songpa
Organization Name (회사명) : Dotname Korea
Organizational Unit Name (부서명) : Digital Certificate Team
Common Name (인증 받을 도메인 주소) : www.도메인.co.kr
Email Address : 
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password : 
An optional company name : 회사명

 

이와 같이 입력한다.

 

6. CSR 확인

[root@web1 ssl]# openssl req -noout -text -in ssl_test.csr
Certificate Request:
    Data:
        Version: 0 (0x0)
        Subject: C=kr, ST=Seoul, L=Songpa, O=Dotname Korea,
        OU=Digital Certificate Team, CN=www.anycert.co.kr
...
[root@web1 ssl]#

 

7. 개인키 백업 및 복사

cp ssl_test.key /usr/local/apache/conf/

cp ssl_test.csr /usr/local/apache/conf/

 

8. 사설 인증서 생성

openssl x509 -req -days 1280 -in ssl_test.csr -signkey  ssl_test.key -out  ssl_test.crt


 

9. 개인키에서 패스워드 삭제하기  (안하면 아파치 시작하거나, 리부팅시 패스워드를 넣어서 start 시켜줘야 한다)

openssl rsa -in ssl_test.key -out ssl_test.key.insecure

10. 아파치 httpd.conf  수정

# Secure (SSL/TLS) connections
#Include conf/extra/httpd-ssl.conf

이부분의 include 주석을 해제한다.

 

# Secure (SSL/TLS) connections
Include conf/extra/httpd-ssl.conf

 

11. httpd_ssl.conf 수정

<VirtualHost _default_:443>

#   General setup for the virtual host
DocumentRoot "/usr/local/apache-2.2.17/htdocs"
ServerName www.example.com:443
ServerAdmin you@example.com
ErrorLog "/usr/local/apache-2.2.17/logs/error_log"
TransferLog "/usr/local/apache-2.2.17/logs/access_log"

위 부분을

<VirtualHost *:443>

#   General setup for the virtual host
#DocumentRoot "/usr/local/apache-2.2.17/htdocs"
DocumentRoot "/home/prod/webroot/sso"
ServerName 도메인:443
ServerAdmin 관리자이메일주소@

ErrorLog "/usr/local/apache-2.2.17/logs/ssl_error_log"
TransferLog "/usr/local/apache-2.2.17/logs/ssl_access_log"

<Directory "/home/prod/webroot/sso">
    Options FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    Allow from All
</Directory>

 

이런식으로 바꿔주고. Directory 설정에 Allow from All 을 넣어줘야 403 에러가 나지 않는다.

 

SSLCertificateFile "/usr/local/apache-2.2.17/conf/server.crt"
위 주소를 변경한다. 만들어놓은것과 같게

SSLCertificateFile "/usr/local/apache-2.2.17/conf/ssl_test.crt"

 

SSLCertificateKeyFile "/usr/local/apache-2.2.17/conf/server.key"
이것도 변경한다

SSLCertificateKeyFile "/usr/local/apache-2.2.17/conf/ssl_test.key"

아파치 재시작

 

※ 만일 아래 에러가 나올경우
Invalid command 'SSLPassPhraseDialog', perhaps misspelled or defined by a module not included in the server configuration


mod_ssl 이 적용되지 않아 나오는 메시지
아파치를 컴파일 할 때  ssl 관련 옵션을 사용하지 않았거나
아파치 컴파일시 다음 옵션 추가
--enable-ssl
--with-ssl=DIR (DIR => open ssl path)

ex ) ./configure --prefix=/usr/local/apache-2.2.17 --enable-ssl --with-ssl=/usr/bin/openssl --enable-so -with-mpm=worker --enable-rewrite --enable-headers

 


httpd.conf 파일에서 해당 모듈인 mod_ssl.so 을 로드 하지 않았거나

(아파치 1 버전대에선 so 파일을 추가해야 한다. 2 버전에는 built in 되어 있으므로 위에 configure 만 다시 해주고 make && make install 까지 해줘야 설치된다.)
LoadModule ssl_module modules/mod_ssl.so

728x90