๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Lect & Tip/Nginx & PHP 7.0

๋ฆฌ๋ˆ…์Šค์—์„œ Mattermost๋ฅผ HTTPS(SSL)๋กœ ์šด์˜ํ•˜๋Š” ๋ฐฉ๋ฒ•

by st๊ณต๊ฐ„ 2024. 8. 15.

๋ชฉ์ฐจ

    ๋ฆฌ๋ˆ…์Šค์—์„œ Mattermost๋ฅผ HTTPS(SSL)๋กœ ์šด์˜ํ•˜๋Š” ๋ฐฉ๋ฒ•

    ๋ฆฌ๋ˆ…์Šค ํ™˜๊ฒฝ์—์„œ Slack์˜ ๋Œ€์•ˆ์œผ๋กœ ์ž๋ฆฌ์žก๊ณ  ์žˆ๋Š” Mattermost๋ฅผ ์„ค์น˜ํ•˜๊ณ  HTTPS(SSL) ๋ชจ๋“œ๋กœ ์šด์˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์†Œ๊ฐœํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์ด์ „ ๊ธ€์—์„œ๋Š” Mattermost์˜ ๊ธฐ๋ณธ ์„ค์น˜ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ๋‹ค๋ฃจ์—ˆ์œผ๋‚˜, ์ด๋ฒˆ์—๋Š” HTTPS๋กœ ๋ณด์•ˆ์„ ๊ฐ•ํ™”ํ•˜์—ฌ Mattermost๋ฅผ ์šด์˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ž์„ธํžˆ ์„ค๋ช…๋“œ๋ฆด ๊ฒƒ์ž…๋‹ˆ๋‹ค. ํ˜„์žฌ ์ €๋Š” Mattermost๋ฅผ HTTPS ๋ชจ๋“œ๋กœ ์„ฑ๊ณต์ ์œผ๋กœ ์šด์˜ ์ค‘์ž…๋‹ˆ๋‹ค. ์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” HTTPS ์„ค์ •์„ ์™„๋ฃŒํ•œ Mattermost์˜ ์ง์ ‘์ ์ธ ์„ค์ • ๋ฐฉ๋ฒ•์„ ์•ˆ๋‚ดํ•˜๋ฉฐ, NGINX ํ”„๋ก์‹œ ์„ค์ • ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ๋Š” ์ถ”ํ›„ ์„ฑ๊ณต ์‹œ ๋ณ„๋„๋กœ ์„ค๋ช…๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค.

    1. ๋„๋ฉ”์ธ ๊ตฌ๋งค

    Mattermost๋ฅผ HTTPS๋กœ ์šด์˜ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋„๋ฉ”์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ๊ฐœ์ธ์ ์œผ๋กœ๋Š” ํ˜ธ์ŠคํŒ….kr์—์„œ ๋„๋ฉ”์ธ์„ ๊ตฌ๋งคํ•˜๊ณ  ์žˆ์œผ๋ฉฐ, ๊ฐ€๊ฒฉ์ด ์ €๋ ดํ•˜๊ณ  ์„œ๋น„์Šค๊ฐ€ ์•ˆ์ •์ ์ž…๋‹ˆ๋‹ค. ๋„๋ฉ”์ธ์„ ๊ตฌ๋งคํ•œ ํ›„, ๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

    2. certbot ์„ค์น˜

    HTTPS๋ฅผ ํ™œ์„ฑํ™”ํ•˜๊ธฐ ์œ„ํ•ด ๋ฌด๋ฃŒ SSL ์ธ์ฆ์„œ์ธ Let's Encrypt๋ฅผ ์‚ฌ์šฉํ•  ๊ณ„ํš์ž…๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด certbot์ด๋ผ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์„ค์น˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. certbot์€ SSL ์ธ์ฆ์„œ๋ฅผ ์ž๋™์œผ๋กœ ๋ฐœ๊ธ‰๋ฐ›๊ณ  ๊ฐฑ์‹ ํ•ด์ฃผ๋Š” ๋„๊ตฌ์ž…๋‹ˆ๋‹ค. ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด certbot๊ณผ NGINX ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค:

    sudo apt update
    sudo apt install certbot python3-certbot-nginx

    NGINX๋Š” ์ด ๊ณผ์ •์—์„œ ํ•„์ˆ˜๋Š” ์•„๋‹ˆ์ง€๋งŒ, ๊ถ๊ทน์ ์œผ๋กœ NGINX๋ฅผ ์‚ฌ์šฉํ•ด Mattermost๋ฅผ HTTPS๋กœ ์šด์˜ํ•  ๊ณ„ํš์ด๋ผ๋ฉด NGINX๋„ ํ•จ๊ป˜ ์„ค์น˜ํ•ด ๋‘๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

    3. Mattermost HTTPS ์„ค์ •

    Mattermost๋ฅผ HTTP๋กœ ์„ฑ๊ณต์ ์œผ๋กœ ์„ค์น˜ํ•œ ํ›„, HTTPS ์„ค์ •์„ ์ง„ํ–‰ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด Mattermost์˜ ์‹œ์Šคํ…œ ์ฝ˜์†”์— ์ ‘์†ํ•˜์—ฌ ๋‹ค์Œ ์„ค์ •์„ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค:

    1. Site URL ์„ค์ •
      • System Console์— ์ ‘์†ํ•œ ํ›„, ENVIRONMENT > Web Server ํ•ญ๋ชฉ์œผ๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.
      • Site URL์„ https://[๊ตฌ๋งคํ•œ๋„๋ฉ”์ธ]:443์œผ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
    2. Listen Address ์„ค์ •
      • Listen Address๋ฅผ :443์œผ๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.
    3. Forward port 80 to 443 ์„ค์ •
      • Forward port 80 to 443์„ true๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
    4. Connection Security ์„ค์ •
      • Connection Security๋ฅผ TLS๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
    5. Use Let's Encrypt ์„ค์ •
      • Use Let's Encrypt๋ฅผ true๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
      ์„ค์ •์„ ๋งˆ์นœ ํ›„, ํ™”๋ฉด ํ•˜๋‹จ์˜ Save ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์—ฌ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

    4. ํฌํŠธ ๋ฐ”์ธ๋”ฉ ๊ถŒํ•œ ์„ค์ •

    Mattermost๊ฐ€ 1000๋ฒˆ๋Œ€ ์ดํ•˜์˜ ํฌํŠธ์—์„œ ์‹คํ–‰๋  ์ˆ˜ ์žˆ๋„๋ก ๊ถŒํ•œ์„ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ด ํฌํŠธ ๋ฐ”์ธ๋”ฉ ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•ฉ๋‹ˆ๋‹ค:

    sudo setcap cap_net_bind_service=+ep /opt/mattermost/bin/mattermost

    ์ด ๋ช…๋ น์–ด๋Š” Mattermost๊ฐ€ 80๋ฒˆ ํฌํŠธ์™€ ๊ฐ™์€ ์ €์œ„ํ—˜ ํฌํŠธ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ถŒํ•œ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ณผ์ •์—์„œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ ์ฃผ์˜ ๊นŠ๊ฒŒ ์ง„ํ–‰ํ•˜์„ธ์š”.

    5. Mattermost ์„œ๋น„์Šค ์žฌ์‹œ์ž‘

    ์„ค์ •์„ ๋งˆ์นœ ํ›„ Mattermost ์„œ๋น„์Šค๋ฅผ ์žฌ์‹œ์ž‘ํ•˜๊ฑฐ๋‚˜ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด Mattermost ์„œ๋น„์Šค๋ฅผ ์žฌ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค:

    sudo systemctl restart mattermost

    ์ด ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด Mattermost๊ฐ€ ์ƒˆ๋กญ๊ฒŒ ์„ค์ •๋œ HTTPS ๋ชจ๋“œ๋กœ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ NGINX์™€์˜ ์ถฉ๋Œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค๋ฉด, NGINX๋ฅผ ์ผ์‹œ์ ์œผ๋กœ ์ค‘์ง€ํ•˜๊ณ  ์ž๋™ ์‹คํ–‰์„ ๋น„ํ™œ์„ฑํ™”ํ•ด์•ผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    6. NGINX ๊ด€๋ จ ์„ค์ • (์ถ”๊ฐ€ ์ •๋ณด)

    Mattermost์™€ NGINX๊ฐ€ ์ถฉ๋Œํ•˜๋Š” ๊ฒฝ์šฐ, NGINX๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์„ค์ •์œผ๋กœ Mattermost๋ฅผ ์šด์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. NGINX๋ฅผ ๋น„ํ™œ์„ฑํ™”ํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค:

    sudo systemctl stop nginx
    sudo systemctl disable nginx

    ๋‹ค๋ฅธ ์›น์‚ฌ์ดํŠธ์™€ ํ•จ๊ป˜ ์šด์˜ํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ, HTTP๋กœ ์šด์˜ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. NGINX ํ”„๋ก์‹œ ์„ค์ •์— ๋Œ€ํ•œ ์ถ”๊ฐ€์ ์ธ ์ •๋ณด๋Š” ์ถ”ํ›„ ๋ณ„๋„์˜ ํฌ์ŠคํŒ…์„ ํ†ตํ•ด ์ œ๊ณตํ•  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.

    ๊ฒฐ๋ก 

    Mattermost๋ฅผ HTTPS ๋ชจ๋“œ๋กœ ์„ค์ •ํ•˜๋ฉด ๋ฐ์ดํ„ฐ ์ „์†ก์˜ ๋ณด์•ˆ์„ ๊ฐ•ํ™”ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์™ธ๋ถ€ ๊ณต๊ฒฉ์— ๋Œ€ํ•œ ๋ฐฉ์–ด๋ ฅ์„ ๋†’์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋„๋ฉ”์ธ ๊ตฌ๋งค, certbot ์„ค์น˜, Mattermost ์‹œ์Šคํ…œ ์„ค์ •, ํฌํŠธ ๋ฐ”์ธ๋”ฉ ๊ถŒํ•œ ์„ค์ •, ๊ทธ๋ฆฌ๊ณ  ์„œ๋น„์Šค ์žฌ์‹œ์ž‘๊นŒ์ง€์˜ ๊ณผ์ •์„ ํ†ตํ•ด HTTPS ํ™˜๊ฒฝ์„ ์„ฑ๊ณต์ ์œผ๋กœ ๊ตฌ์ถ•ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. NGINX์™€์˜ ์ถฉ๋Œ ๋ฌธ์ œ๋Š” ์ถ”๊ฐ€์ ์ธ ์„ค์ •์œผ๋กœ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ด๋ฅผ ์œ„ํ•œ ์ •๋ณด๋Š” ๋ณ„๋„์˜ ํฌ์ŠคํŒ…์—์„œ ๋‹ค๋ฃฐ ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.

    ํ‚ค์›Œ๋“œ: Mattermost, HTTPS, SSL, certbot, Let's Encrypt, Ubuntu, NGINX, ํฌํŠธ ๋ฐ”์ธ๋”ฉ, ๋ฆฌ๋ˆ…์Šค, ๋ณด์•ˆ ์„ค์ •

    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€