sronsemiro.tistory.com/9

 

Ubuntu 18.04.4 LTS, Nginx에 Let's Encrypt 설치 및 HTTPS적용(SSL)

1. Certbot 설치 // add repo $ sudo add-apt-repository ppa:certbot/certbot // install certbot $ sudo apt install python-certbot-nginx 2. HTTPS(SSL)을 설정할, nginx 설정 체크 // check server_name $ su..

sronsemiro.tistory.com

기존 시스템을 유지하고 있었으므로,

Ubuntu 18.04.4 / nginx 로 운영중이다.

 

예전에 작성해두었던, 위 글을 참조해서 오랜만에 SSL을 적용하려고 아래 명령어를 입력했다.

certbot --nginx -d AAA.co.kr -d www.AAA.co.kr

 

그랬더니, 생각보다 오랜 시간이 걸린 후, 아래와 같은 에러 메시지가 나왔다.

Failed authorization procedure. AAA.co.kr (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://AAA.co.kr/.well-known/acme-challenge/96Ot7ZF9cVMwcycFhodd96TXi97sFQ9OR7Ln2sPpwN4 [183.111.125.112]: "\n<!DOCTYPE html>\n<html class=\"html\" lang=\"ko-KR\" itemscope itemtype=\"http://schema.org/WebPage\">\n<head>\n\t<meta charset=\"UTF-8\">\n", www.AAA.co.kr (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://AAA.co.kr/.well-known/acme-challenge/YTz6-bfcu9UWltNrFoqkYxrURdasHSTSePse7oH6zyI [183.111.125.112]: "<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body>\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n<hr><center>ng"

IMPORTANT NOTES:
 - The following errors were reported by the server:

   Domain: AAA.co.kr
   Type:   unauthorized
   Detail: Invalid response from
   http://AAA.co.kr/.well-known/acme-challenge/96Ot7ZF9cVMwcycFhodd96TXi97sFQ9OR7Ln2sPpwN4
   [183.111.125.112]: "\n<!DOCTYPE html>\n<html class=\"html\"
   lang=\"ko-KR\" itemscope
   itemtype=\"http://schema.org/WebPage\">\n<head>\n\t<meta
   charset=\"UTF-8\">\n"

   Domain: www.AAA.co.kr
   Type:   unauthorized
   Detail: Invalid response from
   http://AAA.co.kr/.well-known/acme-challenge/YTz6-bfcu9UWltNrFoqkYxrURdasHSTSePse7oH6zyI
   [183.111.125.112]: "<html>\r\n<head><title>504 Gateway
   Time-out</title></head>\r\n<body>\r\n<center><h1>504 Gateway
   Time-out</h1></center>\r\n<hr><center>ng"

   To fix these errors, please make sure that your domain name was
   entered correctly and the DNS A/AAAA record(s) for that domain
   contain(s) the right IP address.

이전이랑 똑같이 했는데,.. 왜 안되지..?

 

이것저것 찾아보니, 발생할 수 있는 이유는 여러가지가 있었다.

1. 해당 주소가 https로 리다이렉트 되고 있는 경우.

2. 해당 URL의 .well-known/acme-challenge/ <=== 이 경로로 접근이 안되는경우

3. 위 에러코드에도 나오듯이 제대로 된 IP주소가 아니거나 DNS 설정이 잘못된 경우 

등등..

 

근데 나는 아무것도 해당되지 않았다.

그래서 어떻게 해야 할까 고민하다가.

 

인증서만 발급받고 나머지 설정은 수동으로 하는 방법을 찾았고, 시도해봤다.

 

letsencrypt certonly --webroot --webroot-path=/var/www/AAA -d AAA.co.kr -d www.AAA.co.kr

certbot은 인증서를 발급받고, 설정까지 자동으로 해주는 반면

letsencrypt 명령어를 사용하면, 수동으로 설정해줄 수 있다. 

(이게 맞나? 정확히는 모르겠다..)

 

--webroot --webroot-path

여기서 --webroot는 인증서를 발급받을 홈페이지 소스가 있는 폴더의 경로를 적어주면 된다.

 

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for AAA.co.kr
http-01 challenge for www.AAA.co.kr
Using the webroot path /var/www/1800_7058_co_kr for all unmatched domains.
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/AAA.co.kr/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/AAA.co.kr/privkey.pem
   Your cert will expire on 2020-12-18. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 

명령어를 실행하면, 위와 같이 잘 되었다고 나온다.

그러면, /etc/letsencrypt/archive/AAA.co.kr 경로아래에 인증서들이 발급된 것을 확인할 수 있다.

 

그럼 이제, 이 인증서들을 이용해서, nginx에 설정해주면 된다.

server {
 ## 이 부분은 http로 접속하면, https로 리다이렉트 시켜주는 부분이다 ##
 listen 80;
 root /var/www/AAA;
 server_name AAA.co.kr www.AAA.co.kr;

 return       301 https://$server_name$request_uri;
}

server {
 listen 443 ssl http2;
 root /var/www/sbcompany_co_kr;
 server_name AAA.co.kr www.AAA.co.kr;
 index index.php;

 ## 아래 4줄이 아까 발급받은 인증서를 설정 하는 부분이다. ##
 ssl_certificate /etc/letsencrypt/live/AAA.co.kr/fullchain.pem;
 ssl_certificate_key /etc/letsencrypt/live/AAA.co.kr/privkey.pem;
 include /etc/letsencrypt/options-ssl-nginx.conf;
 ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

 modsecurity on;
 modsecurity_rules_file /etc/nginx/modsec/modsec_includes.conf;
 #modsecurity_rules_file /etc/nginx/modsec/modsecurity.conf;

 location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
     access_log        off;
     log_not_found     off;
     expires           360d;
 }

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

 location / {
 try_files $uri $uri/ /index.php?q=uri&$args;
 }

 location ~ \.php$ {
 include snippets/fastcgi-php.conf;
 fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
 }

 location ~ /xmlrpc.php {
  deny all;
  return 444;
 }
}

nginx에 해당 사이트의 site설정에 위 4줄을 추가해주면 된다.

끝~~

 

+ Recent posts