[DevOps] Ubuntu 22.04 LTS Docker Container Install NGINX

2023. 1. 6. 01:04ใ†System ์ž‘์—…์‹ค/DevOps

728x90
๋ฐ˜์‘ํ˜•

 

 

 

 

๐Ÿš€ Ubuntu 22.04 LTS Docker Container์— NGINX ์„ค์น˜ํ•˜๊ธฐ

    ๐Ÿ”ฝ  ๊ฐœ์š”

        ๐Ÿ“ฆ ์†Œ๊ฐœ

์ฃผ๋‹ˆํ•˜๋ž‘์€ ํ˜„์žฌ ์ง„ํ–‰ ์ค‘์ธ Project ๋ชจ์ž„์—์„œ ์—ฌ๋Ÿฌ Server ๊ณ„์ •์„ ํ†ตํ•ฉ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด OpenLDAP์„ Ubuntu 22.04 LTS Docker Container์— ๊ตฌ์„ฑ์„ ํ•˜์˜€๊ณ , ์ด๋ฅผ ํ†ตํ•ด ์—ฌ๋Ÿฌ Client Server์™€ ์—ฐ๋™์„ ํ•˜๋ ค๊ณ  ํ•˜์˜€์–ด์š”.
ํ•˜์ง€๋งŒ, Docker Container๋Š” ๋‹ค๋ฅธ ์™ธ๋ถ€ Server์™€ ํ†ต์‹ ์ด ๊ฐ€๋Šฅํ•œ IP ์ฃผ์†Œ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์ง€ ์•Š์•˜๊ณ , Docker Network์˜ IP์ฃผ์†Œ๋งŒ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์ƒํƒœ๋ผ Client์—์„œ /etc/hosts์— OpenLDAP ๋‚ด์šฉ์„ ๊ธฐ์žฌํ•ด์ฃผ๋Š”๋ฐ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์–ด์š”.

์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด OpenLDAP Container์— NGINX๋ฅผ ์ถ”๊ฐ€๋กœ ์„ค์น˜ํ•˜๊ณ , Reverse Proxy๋ฅผ ํ†ตํ•ด ์—ฐ๊ฒฐ์ด ๋˜๋„๋ก ๊ตฌ์„ฑํ•ด ๋ณด๋ ค๊ณ  ํ•ด์š”.

 

 

 

 

        ๐Ÿ“ฆ ์„ค์น˜ํ•˜๊ธฐ

์ตœ์ดˆ ์ด ์ž‘์—…์„ ์œ„ํ•ด Package ์ตœ์‹ ํ™” ์ž‘์—…์„ ๋จผ์ € ์ง„ํ–‰ํ•ด ์ค„๊ฒŒ์š”.

apt-get update && apt-get upgrade -y



apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring


๊ทธ๋Ÿฐ ๋’ค ์ถ”๊ฐ€์ ์œผ๋กœ ์œ„์˜ Package๋“ค์„ ์„ค์น˜ํ•ด ์ฃผ๋„๋ก ํ• ๊ฒŒ์š”.


์ด๋ฒˆ์—๋Š” NGINX Package๋ฅผ ๊ฒ€์ฆํ•  ์ˆ˜ ์žˆ๋Š” Key๋ฅผ Import ํ•ด ์ค„๊ฑด๋ฐ, ๊ธฐ์กด์—๋Š” apt-key ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•ด์„œ Package๋ฅผ ๋‚ด๋ ค ๋ฐ›์•˜์—ˆ์ง€๋งŒ, deprecated ๋œ ์ƒํƒœ์ด๊ธฐ ๋•Œ๋ฌธ์— ์•„๋ž˜์™€ ๊ฐ™์ด ๋‚ด๋ ค ๋ฐ›์•„ ์ฃผ์—ˆ์–ด์š”.

curl -fsSL https://nginx.org/keys/nginx_signing.key | gpg --dearmor -o /etc/apt/keyrings/nginx-archive-keyring.gpg


๊ทธ๋Ÿฐ ๋’ค ๋‚ด๋ ค ๋ฐ›์€ File์„ ๊ฒ€์ฆํ•ด ์ค„๊ฑด๋ฐ ์ถœ๋ ฅ์—์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 ๊ฐ’์ด ์ถœ๋ ฅ๋˜์–ด์•ผ ํ•ด์š”.

gpg --dry-run --quiet --import --import-options import-show /etc/apt/keyrings/nginx-archive-keyring.gpg



์ด์ œ NGINX์˜ Mainline์˜ Repository๋ฅผ ๋“ฑ๋กํ•ด ์ค„๊ฒŒ์š”.
ํ˜น์‹œ๋ผ๋„ stable Version ์„ค์น˜๋ฅผ ํฌ๋งํ•œ๋‹ค๋ฉด ๋‘๋ฒˆ์งธ ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•ด ์ค„์ˆ˜ ์žˆ์–ด์š”.

echo \"deb http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx\" \\\n| tee /etc/apt/sources.list.d/nginx.list"

 

# NGINX Stable Repository ๋“ฑ๋ก ๋ช…๋ น์–ด

echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
| tee /etc/apt/sources.list.d/nginx.list
728x90

 

curl -fsSL https://nginx.org/keys/nginx_signing.key | apt-key add -


๊ทธ๋Ÿฐ ๋’ค apt Package ์ง„์œ„์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•ด ์ฃผ๋Š” ์ž‘์—…์„ ํ•ด ์ฃผ์—ˆ์–ด์š”.




๋‹ค์‹œ package๋ฅผ ์ตœ์‹ ํ™” ํ•œ ๋’ค
๋ณธ๊ฒฉ์ ์œผ๋กœ NGINX Package๋ฅผ ๋‚ด๋ ค๋ฐ›๊ณ  ์„ค์น˜ํ•ด ๋ณผ๊ฒŒ์š”.

apt-get update && apt-get upgrade -y



apt-get install -y nginx




ํ˜„์žฌ OpenLDAP Container์—๋Š” apache2๋ฅผ ํ†ตํ•ด LDAP Access Admin ์ด๋ผ๋Š” WEB Service๊ฐ€ ๊ตฌ๋™์ค‘์ด๋ผ ์œ„์™€ ๊ฐ™์ด Port ์ถฉ๋Œ๋กœ ์ธํ•ด NGINX๋ฅผ ๊ธฐ๋™ํ•˜์ง€ ๋ชปํ•˜๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์–ด์š”.

์ด์— ๋Œ€ํ•ด apache2 Port ๋ณ€๊ฒฝ์„ ์ง„ํ–‰ํ•ด ์ฃผ์–ด์•ผ ํ•˜๊ณ , ์ด์— ๋Œ€ํ•œ ์ •๋ฆฌ๋Š” ์ด ๊ณณ์— ์ค€๋น„ํ•ด ๋‘๋„๋ก ํ•˜์˜€์–ด์š”.

๋ฐ˜์‘ํ˜•



service nginx start


์œ„์˜ apache2 Port๋ฅผ ๋ณ€๊ฒฝํ•˜๊ณ , ์œ„์™€ ๊ฐ™์ด NGINX Service๋ฅผ ๊ตฌ๋™ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜์—ˆ์–ด์š”.


 

 

 

    ๐Ÿ”ฝ  Reverse Proxy

        ๐Ÿ“ฆ ์„ค์ •ํ•˜๊ธฐ

์ด๋ฒˆ์—๋Š” NGINX๋ฅผ ์„ค์น˜ํ•œ ์ง„์งœ ๋ชฉ์  ๋‹ฌ์„ฑ์„ ์œ„ํ•œ Reverse Proxy ์„ค์ •์„ ์ง„ํ–‰ํ•ด ๋ณผ๊ฒŒ์š”.

vim /etc/nginx/conf.d/default.conf


์ฃผ๋‹ˆํ•˜๋ž‘์€ ์œ„์™€ ๊ฐ™์ด ์„ค์ •์„ ํ•ด์ฃผ์—ˆ์–ด์š”.

์™ธ๋ถ€์—์„œ 1008 Port๋กœ ์š”์ฒญ์ด ๋“ค์–ด์˜ค๋ฉด 389 Port๋กœ ๋„˜๊ฒจ์ง€๋„๋ก ์ฒ˜๋ฆฌํ•œ ๊ฒƒ์ด์—์š”.


service nginx restart


์œ„์™€ ๊ฐ™์ด ์ •์ƒ ์„ค์ •๋œ ๊ฒƒ์„ ํ™•์ธํ•˜์˜€์–ด์š”.





 

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•