메뉴 닫기

mod_ssl 설치 및 설정 (apache 및 nginx)

1. SSL이란

SSL(Secure Sockets Layer)은 데이터를 암호화 하거나 통신상대를 인증함으로써 데이터를 보호합니다.

https://”로 시작하는 URL에서 https는 “HTTP over SSL”의 약자로 httpSSL로 암호화 한 프로토콜입니다.

SSL 통신을 사용함으로써 데이터의 ‘도청’. 데이터의 ‘변조’, 통신상대의 ‘위장’을 방지할 수 있습니다. PC와 서버간의 송수신되는 개인정보를 암호화하여, 해커가 개인정보 데이터를 갈취하더라도 복호화가 불가능하여 개인정보 자체를 보안기술입니다.

쉽게 말해 SSL은 데이터를 암호화해서 주고 받는 것이라고 생각하면 됩니다. SSL은 실제 암호문을 주고 받는 것은 양쪽이 같은 대칭키를 사용합니다. 대칭키를 전송하기 위한 공개키와는 다릅니다.

위와같이 웹서버에 SSL 인증서를 설치할 경우 이 기술이 적용된 전자문서는 별도의 암호화 과정을 거쳐 상대방에게 전달되므로 정보 송신자(웹브라우저에 정보를 입력하는 사용자)와 정보 수신자(해당 사이트의 웹서버 관리자) 외에는 그 내용을 해독할 수 없습니다. 따라서 전자문서가 전송되는 도중에 해커가 Sniffing을 시도한다고 해도 정보가 암호화되어있기 때문에 그 내용을 절대로 파악할 수 없습니다.

 

 

2. Apache에서의 SSL 설치 및 적용

2-1. SSL 적용 전 설치 확인

아파치 2.X 버전의 경우 mod_ssl의 기능이 포함되어있기 때문에 컴파일시 포함 시켜 설치 진행하면 사용할 수 있습니다.

# apachectl -v

Server version: Apache/2.4.3 (Unix) → 아파치 2.4에서 적용하였습니다.

Server built: Dec 27 2017 11:23:25

아파치에서 ssl을 설치하기 위해서는 mod_ssl 모듈이 설치되어 있어야 합니다.

# apachectl –l |grep mod

Compiled in modules:

mod_so.c

동적방식(DSO)로 설치되어있습니다. 정적방식의 경우 mod_ssl.c가 설치되어있는 부분 확인이 가능합니다.

# ll /usr/local/apache/modules |grep ssl

-rwxr-xr-x 1 root root 892300 2017-12-27 11:50 mod_ssl.so

해당 모듈이 확인되면 해당 모듈이 실제로 존재하는지 확인해봅니다.

openssl의 설치버전을 확인합니다.

# rpm -qa |grep openssl

openssl-1.0.1e-57.el6.x86_64

openssl-devel-1.0.1e-57.el6.x86_64

# yum -y install openssl

만약 openssl이 설치되어있지 않다면 yum으로 설치를 진행합니다.

2-2. 개인키 생성

# mkdir /home/its-you.xyz/ssl

# cd ssl

# pwd

/home/test.xyz/ssl

ssl 인증서를 보관할 디렉터리를 생성 후 이동합니다

# openssl genrsa -des3 -out test.key 2048

Generating RSA private key, 2048 bit long modulus

개인키를 생성합니다. 2010년부터 1024bit의 발급이 중단되었기 때문에 2048bit로 생성해야합니다.

………………………………+++

………..+++

e is 65537 (0x10001)

Enter pass phrase for test.key: [패스워드 입력]

Verifying – Enter pass phrase for test.key: [패스워드 재입력]

# openssl rsa -noout -text -in test.key

성된 개인키 확인은 위 명령어를 통해 확인이 가능합니다.

Enter pass phrase for test.key: [패스워드 입력]

Private-Key: (2048 bit)

 

 

2-3. CSR 생성 및 확인

CSR 값을 생성합니다.

# openssl req -new -key test.key -out test.csr

Enter pass phrase for test.key: [패스워드 입력]

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) []:Seoul ,

Locality Name (eg, city) [Default City]:Geumcheongu

Organization Name (eg, company) [Default Company Ltd]:SMILESERV 기관명

Organizational Unit Name (eg, section) []:Technical Support Team 부서명

Common Name (eg, your name or your server’s hostname) []:test.xyz 도메인주소

Email Address []:admin@test.com 이메일 주소

Please enter the following ‘extra’ attributes

to be sent with your certificate request

A challenge password []: → 아무것도 입력하지 않고 엔터

An optional company name []: → 아무것도 입력하지 않고 엔터

생성된 CSR 값을 확인합니다.

# cat test.csr

csr파일을 코모도 등과 같은 인증기관에 해당 값을 보냅니다. , beginend가 모두 포함되어 있어야 합니다.

2-4. httpd.conf 설정

LoadModule ssl_module modules/mod_ssl.so

LoadModule socache_shmcb_module modules/mod_socache_shmcb.so

mod_sslmod_socache_shmcb 모듈을 활성화합니다.

Include conf/extra/httpd-ssl.conf

httpd-ssl.conf를 사용할 수 있도록 활성화 시킵니다.

2-5. httpd-ssl.conf 설정

# vi /usr/local/apache/conf/extra/httpd-ssl.conf

<VirtualHost *:443>

DocumentRoot “/home/test.xyz/” → 홈소스 위치

ServerName test.xyz

ServerAdmin admin@test.com

ErrorLog “/usr/local/apache/logs/test.xyz_error_log”

TransferLog “/usr/local/apache/logs/test.xyz_access_log”

SSLEngine on

SSLCertificateFile “/etc/letsencrypt/live/test.xyz/fullchain.pem” → 서버인증서+체인인증서

SSLCertificateKeyFile “/etc/letsencrypt/live/test.xyz/privkey.pem” → 개인키

2-6. 방화벽 설정

# iptables -nL |grep 443

ACCEPT tcp — 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:443

SSL의 경우 기본적으로 443포트를 사용중이기 때문에 방화벽에 443 포트 설정 후 iptables를 재시작합니다.

# netstat -nltp |grep 443

tcp 0 0 :::443 :::* LISTEN 16550/httpd

아파치 데몬 재시작 후 정상적으로 데몬이 올라와있는지 확인합니다. 데몬 재시작 전 syntax 구문 에러 검사 후 진행해야 합니다.

 

3. Nginx에서의 SSL 설정


3-1. SSL
적용 전 설치 확인

# /usr/local/nginx/sbin/nginx -v

nginx version: nginx/1.13.4 → Nginx 1.13 버전에서 설치진행하였습니다.


3-2. let’s encrypt
설치

# yum install git → git 패키지를 설치합니다.

# cd /usr/local/src

# git clone https://github.com/letsencrypt/letsencrypt letsencrypt를 설치합니다.

# cd /usr/local/src/letsencrypt

# ./letsencrypt-auto –-help 다운받은 폴더로 이동 후 해당 명령어을 실행하면 자동으로 관련 의존성을 다운받아서 설치됩니다.

#./letsencrypt-auto certonly –a webroot –agree-tos –m [이메일주소] -w [홈소스위치] -d [SSL 발급도메 인명] –rsa-key-size 4096

발급을 원하는 도메인은 반드시 웹접속이 가능한 상태여야합니다.


3-3. let’s encrypt
확인

# pwd

/etc/letsencrypt/live/test.xyz → 해당 경로에 인증서 파일이 생성됩니다.

# ll


3-4. nginx.conf 설정

# vi /usr/local/nginx/conf/nginx.conf

server {

listen 443 ssl;

server_name test.its-you.xyz;

ssl on;

ssl_certificate /etc/letsencrypt/archive/test.its-you.xyz/cert1.pem;

ssl_certificate_key /etc/letsencrypt/archive/test.its-you.xyz/privkey1.pem;

ssl_session_cache shared:SSL:1m;

ssl_session_timeout 5m;

ssl_ciphers HIGH:!aNULL:!MD5;

ssl_prefer_server_ciphers on;

location / {

root html;

index index.html index.htm;

}

}

 

 

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x