GCP에 Let’s encrypt 인증서 적용하여 HTTPS로 변경하기

GCP에 Let’s encrypt 인증서 적용하여 HTTPS로 변경하기

목표

구글클라우드플랫폼(GCP)의 compute engline 인스턴스에서 http에서 https로 보안연결하고자 한다.

서버끼리 데이터 교환이 필요한 상황에서 전달해주는 쪽이나 전달받는 쪽이 HTTPS 혹은 HTTP든 하나로 통일되어야 데이터통신을 할수 있기때문

환경

GCP compute Engine 인스턴스, CentOS 7, Apache 2.4.6, Laravel 5.5

STEP 1. 인증서 설치

90일동안 유효한 인증서를 무료 발급받을 수 있는 let’s encrypt를 채택

인증서설치를 위해 Certbot과 mod_ssl을 먼저 설치

sudo yum install epel-release sudo yum install certbot python2-certbot-apache mod_ssl

STEP 2. 가상호스트 설정하기

80번 포트를 사용하는 ip번호와 함께 사용할 도메인(가상 호스트)를 설정

sudo vi /etc/httpd/conf/httpd.conf httpd.conf 파일 내부 맨 하단에 작성 include /etc/httpd/conf/vhost.conf AllowOverride None Require all granted

CentOS의 패키지 설치도구인 yum을 사용해서 아파치설치했었다면 가상호스트 관리파일이 없다. 그렇기 떄문에 직접 파일을 만들고 코드를 직접 넣어줘야함.

sdudo vi /etc/httpd/conf/vhost.conf # ServerAdmin [email protected] DocumentRoot /var/www/html/blog/public (아파치에서 설정한 index폴더위치로 지정해주면 됨) ServerName example.com (가상호스트로 쓰는 도메인주소) ServerAlias example.com (가상호스트로 쓰는 도메인주소) # ErrorLog logs/dummy-host.example.com-error_log # CustomLog logs/dummy-host.example.com-access_log common 가상 호스트 주소가 더많다면 위의 코드하단에 동일하게 서버이름만 변경해서 작성해주면 된다.

STEP 3. 증명서 얻기

STEP1 진행후 Certbot이 철치되고 이젠 SSL 인증서를 요청해서 사용

sudo certbot --apache -d example.com(사용자의 도메인) sudo certbot --apache

# 설치하다보면 아래와같은 선택지가나오는데 2번으로 설정해주면 https로 바로 리다이렉트된다. Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: No redirect - Make no further changes to the webserver configuration. 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate number [1-2] then [enter] (press 'c' to cancel):2 # 입력후 아래와 같은 문장이 나온다면 https 적용이 완료된것 IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/example.com/fullchain.

STEP 4. 적용되었는지 확인

적용하려는 도메인에 접속하게되고 도메인주소옆 자물쇠모양이 뜬다면 성공

from http://xerar.tistory.com/39 by ccl(A) rewrite - 2020-03-31 23:25:57