본문 바로가기
서버/개발환경

openssl 설치하기

by 아카이sun 2018. 9. 6.

 해당글은 디지털오션과 nginx 그리고 우분투 16.04를 기준으로 작성되었습니다.


openssl을 사용함에 있어서 certbot을 사용하면 편리하다.


다양한 서버셋팅등에 대해서 편리하게 작성하려면 하단의 사이트 중 하나를 참고하자.


1. https://certbot.eff.org/lets-encrypt/ubuntuxenial-nginx

2. https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04



우선 선행되어야할 설치방법은 다음과 같다.

$ apt-get update
$ apt-get install software-properties-common
$ add-apt-repository universe
$ add-apt-repository ppa:certbot/certbot
$ apt-get update
$ apt-get install certbot python-certbot-nginx 


설치가 완료되었다면 인증서를 발급받자. 


$ certbot --nginx // 도메인을 직접 입력하는 방법

$ certbot --nginx -d example.com -d www.example.com //다수의 인증서받는법

이제 nginx의 서버블록을 다음과 같이 수정하자.

server {

  listen 443 default ssl; 

  listen [::]:443 default ssl; 

  

  ssl_certificate /etc/letsencrypt/live/www.site.com/fullchain.pem;

  ssl_certificate_key /etc/letsencrypt/live/www.site.com//privkey.pem;

  

  server_name  www.sitecom;

  

  access_log  /var/log/nginx/blog.access.log;

  error_log  /var/log/nginx/blog.error.log;


index index.php index.html index.htm index.nginx-debian.html;


  root /var/www;

  

  location / {

      

  }

  

  location /site{

     try_files $uri $uri/ /site/index.php?/$request_uri;

  }


  location ~ \.php$ {

      try_files $uri =404;

      fastcgi_split_path_info ^(.+\.php)(/.+)$;

      fastcgi_pass   unix:/run/php/php7.0-fpm.sock;

      fastcgi_index  index.php;

      fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

      include        fastcgi_params;

  }

  location ~ /\.ht {

      deny all;

  }


}


여기서 중요한점은 

다음부분인데 적용하지 않으면 서버가 정상적으로 작동하지 않을 수 있다.

ssl_certificate /etc/letsencrypt/live/www.site.com/fullchain.pem;

ssl_certificate_key /etc/letsencrypt/live/www.site.com//privkey.pem;

이제 nginx를 재시작 해보자

$ systemctl reload nginx

openssl은 무료다보니 90일까지 사용가능하며 그 이후에는 연장을 해야한다.

* 인증서의 갱신은 만료일 30일전 부터 가능하다.

인증서 체크하기


$ certbot certificates


인증서 삭제하기

$ certbot delete
인증서의 수동갱신

certbot renew --dry-run



- 인증서 자동갱신 with crontab


//매월 1일 1시에 크론탭실행

0 1 1 * * /usr/bin/certbot renew --quiet --renew-hook "service nginx reload" 




'서버 > 개발환경' 카테고리의 다른 글

리눅스에서 백그라운드 등록하기.  (0) 2021.04.08
리눅스에 크롬 설치하기  (0) 2018.09.29
nginx로 멀티도메인  (0) 2018.09.06
도커 설치하기  (0) 2018.08.17
yum 실행시 오류  (0) 2018.02.21

댓글