반응형

안녕하세요 가야태자 @talkit 입니다. 

오늘은 NGINX의 SSL 설정 마지막 입니다. 

일반적으로 저는 아파치에 SSL설정을 많이 했습니다. 

그런데 무료로 한게 아니고 대부분 돈을 내고 인증서를 샀습니다. 그리고 1년에 한번 갱신하는 형태로 진행을 했습니다. 

그런데, Let's Encrypt는 무료이고 3개월에 한번씩 갱신을 해줘야 합니다. 

 Crontab의 사용법

오늘은 간단한 사용법을 알려 드리고, Crontab 만으로 다른 글을 하나 더 적도록 하겠습니다. 

crontab에 스케쥴을 등록해보자. 

sudo crontab -e

음 위 명령어를 입력 합니다. 

 sudo crontab -e
[sudo] password for talkit:
no crontab for root - using an empty one

Select an editor.  To change later, run 'select-editor'.
  1. /bin/nano        <---- easiest
  2. /usr/bin/vim.tiny
  3. /bin/ed

Choose 1-3 [1]:

crontab 을 처음 수행하면 무슨 편집기로 편집 할꺼냐고 묻습니다. 

저희는 vi를 쓸줄 안다고 생각하고 ^^

2번을 선택 합니다. ^^

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
~
~
~
~

위와 같이 나올껍니다. 

vi는 계속 알려 드려야 하는데 일단 

:$를 입력하시고 엔터 치십시오

그러면 맨 마지막줄로 갈껍니다. 

그리고 o 키를 누르신 다음

0 5 * * * /usr/bin/certbot renew --quiet

요렇게 해주면 인증서 만료일이 30일이내면 자동으로 매일 새벽 5시에 인증서를 갱신합니다. 자동 갱신 후에는 다시 30일이 남아야 갱신을 하겠죠 ^^

그런데, 여기서 힌트를 하나 얻어야 합니다. 

저 같은경우는 늘 컴퓨터를 켜두는 편이긴 한데 켜두질 않는 경우는 수동으로 하면 되겠지요 ^^

수동 재 갱신도 

/usr/bin/certbot renew

이렇게 해주면 될 것 같습니다. ^^

글을 적을 꺼리가 많아져서 좋네요 ^^

오늘은 여기까지 하구요.

또 다음 글에서 뵙겠습니다. 

감사합니다. 

 

반응형
반응형

안녕하세요 가야태자 @talkit 입니다. 

NGINX 관련 문서들을 열심히 적고 있습니다. 

오늘은 위 그림에서 보이는 Not secure를 해결하고자 합니다. 

선행과정

리눅스 설치하기

리눅스/Linux VMWARE에 우분투/Ubuntu 20.04 설치하기/Install https://talkit.tistory.com/677

리눅스/Linux VMWARE에 우분투/Ubuntu 18.04 설치하기/Install https://talkit.tistory.com/637

위두 글을 이용해서 VMWARE에 리눅스를 설치 하십시오.

NGINX 설치하기 

리눅스/Linux 우분투에 NGINX Web server 설치하기 How to install NGINX Web server on Ubuntu Linux.  https://talkit.tistory.com/700 

위글을 참고 하시면 됩니다. 

도메인 이름 구매하기

https://www.hosting.kr 

 

글로벌 IT 파트너 - 호스팅케이알(HK)

KISA 고객만족도 최다 선정, 도메인 최저가 제공, 기업/공공도메인, 도메인연결/웹호스팅 무료, 서버, 아마존클라우드(AWS), G Suite, 홈페이지제작 1644-7378

www.hosting.kr

요즘 저기가 도메인이 저렴 한 것 같습니다. 

저는 어제 도메인을 하나 구매 했습니다. ^^

SSL이 IP(아이이) 기반으로 인증이 안되기 때문에 도메인을 구매 하셔야 합니다. 

NGINX 서버블락(Server Block) 설정

리눅스/Linux NGINX 웹서버 설정하기 How to configure NGINX Documents Files.  https://talkit.tistory.com/701

제 글을 계속 읽고 계신다면, 위 글이 서버 블락에 대해서 설명하고 있습니다. 

example.com 대신에 구매하신 도메인 관련 서버블락으로 만드시면 됙, default를 지우셨듯이 example.com 파일을 지우고 새로운 파일을 넣으시면 됩니다. ^^

그러면 이제 실제로 우리가 하고자는 SSL 설정을 시작 해보겠습니다. 

Let's Encrypt를 통한 SSL 설정하기

Certbot를 설치 합니다. 

sudo apt update

습관적으로 계속 한다고 생각 하시면 되구요.

sudo apt install certbot python3-certbot-nginx

서트봇 관련 패키지와 플러그인을 설치 합니다. 

저는 설치가 잘되었습니다. 이번에는 너무 길이서 ^^

server_name example.com www.example.com;

서버네임을 변경하는 과정인데 저는 도메인을 하나 따서 진행 합니다.  example.com 대신에 제 실제 도메인을 넣었습니다. 

여러분들도 실제로 구매하신 도메인을 넣어셔야 합니다. 

혹시 DNS 설정과 관련된 문제는 제가 다른 글에서 한번 써보겠습니다. 

방화벽 설정

이번에도 생략 합니다. ^^

SSL/TLS 인증서 획득하기

sudo certbot --nginx -d example.com -d www.example.com
 sudo certbot --nginx -d example.com -d www.example.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for example.com
Waiting for verification...
Challenge failed for domain example.com
http-01 challenge for example.com
Cleaning up challenges
Some challenges have failed.

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

   Domain: example.com
   Type:   connection
   Detail: 공인아이피: Fetching
   http://example.com/.well-known/acme-challenge/f8kAgZFm0jvoMhu3mbtN5F7IS7B7xcXupFP1XN7C-NU:
   Timeout during connect (likely firewall problem)

   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. Additionally, please check that
   your computer has a publicly routable IP address and that no
   firewalls are preventing the server from communicating with the
   client. If you're using the webroot plugin, you should also verify
   that you are serving files from the webroot path you provided.
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.

저는 집에 있는 컴픀터에 SSL인증 중이라서 ^^ 오류가 나네요 T.T 제가 보안 때문에  몇가지 검사를 위해서 서버에 접속을 했는데 접속이 안된답니다. ^^

그래서 저는 IP타임 공유기의 설정을 변경해서 다시 아래 명령어를 수행 했습니다. 

 

 sudo systemctl restart nginx
talkit@ubuntu:~$ sudo certbot --nginx -d example.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/example.com

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
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/example.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/example.com/privkey.pem
   Your cert will expire on 2023-04-01. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. 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

위와 같이 성공 했습니다. 

오 ^^

오 저 앞에 Not secure가 없어졌습니다. ^^

이번 글은 여기까지 하고, 다음글에서는  Let's Encrypt의 갱신 자동화에 대해서 글을 또하나 적어보고, 또한 도메인 구매와 도메인 설정(DNS)에 관해서 알아보겠습니다. 

감사합니다. 

반응형

+ Recent posts