certbot ssl nginx - RLidea/dev.docs GitHub Wiki

Certbot ์œผ๋กœ Nginx์— Letโ€™s Encrypt SSL ์ ์šฉํ•˜๊ธฐ

ํ™˜๊ฒฝ:

OS: Ubuntu 18.04.3 LTS

certbot ์„ค์น˜

$ sudo apt-get update  # ์ €์žฅ์†Œ ์—…๋ฐ์ดํŠธ
$ sudo add-apt-repository ppa:certbot/certbot  # certbot ์ €์žฅ์†Œ ์ถ”๊ฐ€
$ sudo apt-get update  # ์ €์žฅ์†Œ ์—…๋ฐ์ดํŠธ
$ sudo apt-get install -y python3-certbot-nginx  # certbot ์„ค์น˜

์ž˜ ์„ค์น˜๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ด๋ณด์ž.

$ certbot --version
certbot 0.31.0

certbot ์‹คํ–‰

$ sudo certbot --nginx

์ด๋ฉ”์ผ, ์•ฝ๊ด€(a), ๋ฉ”์ผ ์ˆ˜์‹  ์—ฌ๋ถ€(n), ๋„๋ฉ”์ธ(enter), http ํ†ต์‹ ์‹œ s๋กœ ๋ฆฌ๋””๋ ‰์…˜ ์—ฌ๋ถ€(y or 2)๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ๋ฌผ์–ด๋ณธ๋‹ค.

์œ„ ๊ณผ์ •์„ ๊ฑฐ์น˜๋ฉด ssl์ด ์ ์šฉ๋œ๋‹ค.

์ธ์ฆ์„œ ์ž๋™ ๊ฐฑ์‹ 

crontab ์„ ์ด์šฉํ•ด์„œ ๊ฐฑ์‹  ์ž๋™ํ™”

$ crontab -e

์•„๋ž˜ ๋‚ด์šฉ์„ ์ถ”๊ฐ€ (๋งค์ผ ์˜ค์ „ 5์‹œ์— ๊ฐฑ์‹ )

0 5 * * * root test -x /usr/bin/certbot  -a \! -d /run/systemd/system &&  perl -e 'sleep int(rand(43200))' &&  certbot -q renew

Trouble Shooting

Certbot ์‹คํ–‰์‹œ ์—๋Ÿฌ

๋•Œ๋•Œ๋กœ ์•„๋ž˜ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•จ.

$ sudo certbot --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Error while running nginx -c /etc/nginx/nginx.conf -t.

nginx: [emerg] unknown "connection_upgrade" variable
nginx: configuration file /etc/nginx/nginx.conf test failed

The nginx plugin is not working; there may be problems with your existing configuration.
The error was: MisconfigurationError('Error while running nginx -c /etc/nginx/nginx.conf -t.\n\nnginx: [emerg] unknown "connection_upgrade" variable\nnginx: configuration file /etc/nginx/nginx.conf test failed\n',)

solution:

sudo vi /etc/nginx/nginx.conf์— ์•„๋ž˜ ๋‚ด์šฉ์„ ์ถ”๊ฐ€ (map ํ•จ์ˆ˜๋งŒ ์ถ”๊ฐ€ํ•˜๋ฉด ๋จ.)

http {
    map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
   }

    server {
        location / {
                    #โ€ฆ
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection $connection_upgrade;
            }
        }
}

ref: https://developpaper.com/nginx-emerg-unknown-connection_upgrade-variable-solution-and-thinking/