2015년 1월 6일 화요일

Nginx + OpenSSL 설치 SSL 인증서 만들기



키 생성

개인 키 (.key) 와 인증서 서명 요청 파일 (.csr)을 생성

# openssl req -new -newkey rsa:2048 -nodes -keyout <파일명>.key -out <파일명>l.csr

Generating a 2048 bit RSA private key
.....................+++
................................................+++
writing new private key to '<파일명>l.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) [AU]:KR(국가코드)
State or Province Name (full name) [Some-State]:Korea(국가)
Locality Name (eg, city) []:Seout(지역)
Organization Name (eg, company) [Internet Widgits Pty Ltd]:<회사명>
Organizational Unit Name (eg, section) []:<부서명>
Common Name (e.g. server FQDN or YOUR name) []:<name>
Email Address []:<이메일>

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:<비밀번호>
An optional company name []:<비밀번호>




#ls -al

-rw-r--r--.  1 root root     1070 Jan  7 14:55 nell.csr

-rw-r--r--.  1 root root     1708 Jan  7 14:55 nell.key


자체 서명된 SSL 인증서를 생성

# openssl x509 -req -days 365 -in <파일명>.csr -signkey <파일명>.key -out <파일명>.crt

Signature ok
subject=/C=KR/ST=Seout/L=Seout/O=xxxx/OU=Dev./CN=www.neel.pe.kr/emailAddress=nell@pe.kr

Getting Private key



웹서버 인증서 파일 (.crt) 파일이 만들어짐


# ll
-rw-r--r--.  1 root root     1265 Jan  7 15:02 nell.crt
-rw-r--r--.  1 root root     1070 Jan  7 14:55 nell.csr
-rw-r--r--.  1 root root     1708 Jan  7 14:55 nell.key




서버가 구동될때마다 개인 키에 설정된 PassPhrase를 물어보게 되므로 자동으로 모두 처리되도록 하기 위해 PassPhrase 제거


# cp nell.key nell.key.secure

# openssl rsa -in <파일명>.key.secure -out <파일명>.key
writing RSA key





-------------------------------------------------------




Nginx에 SSL 적용!



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

# HTTPS 부분에 아랫부분을 변경하여 준다.



    # HTTPS server

        server {
         listen       443;
         server_name  localhost;


         ssl     on;
         ssl_certificate /usr/local/nginx/ssl/nell.crt;                  //   crt 경로)
         ssl_certificate_key     /usr/local/nginx/ssl/nell.key;       //   key 경로


         ssl_session_timeout  5m;


         ssl_protocols SSLv2 SSLv3 TLSv1;
         ssl_ciphers              ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP
         ssl_prefer_server_ciphers   on;

        location / {
            root   html;       // 홈페이지 경로
            index  index.html index.htm;
        }
    }
}







nginx에 ssl 모듈 확인






#/usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.7.8
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module


"--with-http_ssl_module" 이부분이 없다면 모듈을 설치해 줘여한다.




모듈 컴파일


#cd /usr/local/src/nginx-1.7.9

# ./configure --prefix=/usr/local/nginx --with-http_ssl_module

# make && make install



# /etc/init.d/nginx configtest
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful


"syntax is ok"가 뜬다면 정상이라는 뜻이다.




#/etc/init.d/nginx restart


웹에서 https:// xxxxxxx 확인


인증이 되지 않는 서버라는 문구가 URL 창에 뜨고 인증보기를 누르면 좀 전에 생성한

정보가 기록되어 있다.










댓글 1개:

Unknown :

감사합니다.
그런데, 앞쪽에
# openssl req -new -newkey rsa:2048 -nodes -keyout .key -out l.csr
에서 마지막의 l.csr 에 "l" 이 들어간 것은 오탈자죠?