[DevOps] NGINX๋ž€?

2022. 10. 7. 00:02ใ†System ์ž‘์—…์‹ค/Docker

728x90
๋ฐ˜์‘ํ˜•

 

 

 




 

 

 

๐Ÿš€ NGINX

    ๐Ÿ”ฝ  NGINX๋ž€?

        ๐Ÿ“ฆ ๊ฐœ์š”

NGINX๋Š” ๋งŽ์€ ๊ธฐ๋Šฅ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” Software๋กœ Revers Proxy, Load balancer, Cache ๋“ฑ์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” Software์—์š”.

๋˜ํ•œ NGINX๋Š” ๋ฐ๋ชฌ์œผ๋กœ ๋™์ž‘ํ•˜๋Š”๋ฐ, ๋ฐ๋ชฌ์ด๋ž€ ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ์‹คํ–‰๋˜๋Š” Service์— ๋Œ€ํ•œ ์šฉ์–ด์—์š”. ๋ชจ๋“  ์„œ๋น„์Šค์—์„œ ์‹คํ–‰๋˜๋Š” Service์™€ OS ์‹œ์ž‘ ์ค‘์— ์ž๋™์œผ๋กœ ์‹œ์ž‘ํ•˜๋„๋ก ๋ฐ๋ชฌ์„ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์–ด์š”.

์ถœ์ฒ˜: https://www.nginx.com/resources/glossary/nginx


NGINX๋Š” ๋‘๊ฐœ์˜ Process๋กœ ๊ตฌ๋™์ด ๋˜์š”.
์ฆ‰, Master Process์™€ Worker Process๋กœ ์ž๋™ ๊ตฌ๋™์ด ๋˜์š”.


์ถœ์ฒ˜ : https://nginx.org/en/docs/beginners_guide.html



์ถœ์ฒ˜ : https://www.youtube.com/watch?v=hA0cxENGBQQ


NGINX ์ฒ˜๋ฆฌ ๊ณผ์ •์„ ์ข€ ๋” ์‚ดํŽด๋ณด๋ฉด ์ตœ์ดˆ Client๊ฐ€ ์š”์ฒญ(Request)๋ฅผ ๋ณด๋‚ด๊ฒŒ ๋˜๋ฉด, NGINX Master Process๊ฐ€ ์ด ์š”์ฒญ์„ ๋ฐ›๊ณ , ์–ด๋–ค ์ž‘์—…์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹Œ ๋ฐ”๋กœ Worker Process์—๊ฒŒ ์ „๋‹ฌ์„ ํ•˜๊ฒŒ๋˜๊ณ , Worker Process๊ฐ€ ์ด๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌ๋™์ด ๋˜๊ณ  ์žˆ์–ด์š”.


{"originWidth":3038,"originHeight":142,"style":"CDM","link":" grep nginx ","caption":"ps aux --forest

728x90



๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ
--forest: Process์— ๋ถ€๋ชจ, ์ž์‹ ๊ฐ„์˜ ๊ด€๊ณ„๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋Š” Option.



Master Process๋Š” ๋ถ€๋ชจ Process๋กœ ์‹คํ–‰์ด ๋˜๊ณ , Woker Process๋Š” ์ž์‹ Process๋กœ ์‹คํ–‰์ด ๋˜๋Š”๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.

/etc/nginx/nginx.conf์—์„œ ์ž์‹ Process ๊ฐœ์ˆ˜๋ฅผ ๋Š˜๋ฆฌ๊ฑฐ๋‚˜, ์ค„์ผ์ˆ˜ ์žˆ์–ด์š”.


vim /etc/nginx/nginx.conf

๋ฐ˜์‘ํ˜•


์œ„์˜ ์„ค์ • File์—์„œ ๋‘๋ฒˆ์งธ ์ค„์„ ๋ณด๋ฉด worker_processes๊ฐ€ auto๋กœ ๋˜์–ด ์žˆ๋Š”๊ฑธ ๋ณผ ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด๋Š” ๊ตฌ๋™ํ•˜๋Š” PC์˜ CPU Core์— ๋”ฐ๋ผ ์ž๋™์œผ๋กœ ํ• ๋‹น ๋ฐ›๊ฒ ๋‹ค๋Š” ์˜๋ฏธ์—์š”. 

vim /etc/nginx/nginx.conf


์œ„์™€ ๊ฐ™์ด ์„ค์ •ํ•˜๊ฒŒ ๋˜๋ฉด ์ž์‹ Process ์ฆ‰, Worker Process๋ฅผ ๋‘ ๊ฐœ๋กœ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด์š”.

์—ฌ๊ธฐ์„œ ์šฐ๋ฆฌ๊ฐ€ ์•Œ ์ˆ˜ ์žˆ๋Š” ๊ฑด NGINX์— ๊ด€๋ จ ์„ค์ •์„ ํ•  ๋•Œ๋Š” nginx.conf๋ฅผ ๊ฑด๋“œ๋ ค ์ฃผ๋ฉด ๋œ๋‹ค๋Š” ์ ์ด์—์š”.






        ๐Ÿ“ฆ Configure File

1. ์„ค์ • ํŒŒ์ผ์€ /etc/nginx/nginx.conf
2. ์„ค์ • ํŒŒ์ผ์€ Directives(๋””๋ ‰ํ‹ฐ๋ธŒ)๋กœ ๊ด€๋ฆฌ

   โˆ™ Simple(๊ฐ„๋‹จ) ๋””๋ ‰ํ‹ฐ๋ธŒ์™€ Block(๋ธ”๋ก) ๋””๋ ‰ํ‹ฐ๋ธŒ๋กœ ๋ถ„๋ฅ˜
     - Block Directive
        ๋ธ”๋ก(์ค‘ ๊ด„ํ˜ธ)์œผ๋กœ ๊ฐ์‹ธ์ ธ ์žˆ์œผ๋ฉด ๋ธ”๋ก ๋””๋ ‰ํ‹ฐ๋ธŒ์ด๊ณ , ์•ˆ ๊ฐ์‹ธ์ ธ ์žˆ์œผ๋ฉด Simple ๋””๋ ‰ํ‹ฐ๋ธŒ

์ถœ์ฒ˜ : https://nginx.org/en/docs/beginners_guide.html



3. ์„ค์ •์˜ ๋์€ ์„ธ๋ฏธ์ฝœ๋ก (;)์œผ๋กœ ๋งˆ๋ฌด๋ฆฌ ๋ฐ ํ‘œ์‹œ


์ถœ์ฒ˜ : https://nginx.org/en/docs/beginners_guide.html



4. Include ์ด์šฉํ•˜์—ฌ ์„ค์ • ํŒŒ์ผ ๋ถ„๋ฆฌ ๊ด€๋ฆฌ

์ถœ์ฒ˜ : https://www.youtube.com/watch?v=hA0cxENGBQQ


NGINX ์„ค์ •์„ nginx.conf์—๋งŒ ํ•˜๊ฒŒ ๋˜๋ฉด ๋งŽ์€ ๋Ÿ‰์— Script ๋ฌธ์ด ๋“ค์–ด๊ฐ€๊ฒŒ ๋  ์ˆ˜๋„ ์žˆ์–ด์š”.
์ด๋Ÿฌํ•œ ์ด์œ ๋กœ ์„ค์ • ํŒŒ์ผ์„ ๋ถ„๋ฆฌํ•ด์„œ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ์œ„์™€ ๊ฐ™์ด include ๋ฌธ์„ ์จ์„œ ํ•ด๋‹น conf File์— ์œ„์น˜๋ฅผ ์ง€์ •ํ•ด ์ฃผ๋ฉด ๋˜์š”.





        ๐Ÿ“ฆ Server Block์ด๋ž€?

1. Server ๊ธฐ๋Šฅ ์„ค์ •.
2. ์–ด๋–ค Address:Port๋กœ Request(์š”์ฒญ)์„ ๋ฐ›์„์ง€ ๊ฒฐ์ •.

์ถœ์ฒ˜ : https://www.youtube.com/watch?v=hA0cxENGBQQ


์œ„์˜ ๊ทธ๋ฆผ์—์„œ ์ฒ˜๋Ÿผ Client๊ฐ€ NGINX์—๊ฒŒ helloworld.com:80์œผ๋กœ ์–ด๋–ค ์š”์ฒญ์„ ๋ณด๋‚ผ์ˆ˜๋„ ์žˆ๊ณ ,
example.com:81๋กœ ์š”์ฒญ์„ ๋ณด๋‚ผ์ˆ˜๋„ ์žˆ์–ด์š”.

์ถœ์ฒ˜ : https://www.youtube.com/watch?v=hA0cxENGBQQ


์œ„์™€ ๊ฐ™์ด ์š”์ฒญ์„ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋Š” ์ด์œ ๋Š” ๊ฐ๊ฐ์˜ Server Block์„ ์ด์šฉํ•ด์„œ listen์„ ํ†ตํ•ด ํ•ด๋‹น Service๊ฐ€ ์š”์ฒญ์„ ๋ฐ›์„ Port๋ฅผ ์ง€์ •ํ•˜๊ณ , server_name์„ ํ†ตํ•ด URL์„ ์ง€์ •ํ•ด ์ฃผ์—ˆ๊ธฐ ๋•Œ๋ฌธ์ด์—์š”.

์œ„์—์„œ server๋Š” ๋ธ”๋ก ๋””๋ ‰ํ‹ฐ๋ธŒ์ธ๋ฐ, listen, server_name์€ ๊ฐ„๋‹จ ๋””๋ ‰ํ‹ฐ๋ธŒ์—์š”. 

์œ„์˜ Script๋ฅผ ๋ถ„์„ํ•ด ๋ณด๋ฉด www.example.org์— 80 Port๋กœ ์š”์ฒญ์ด ๋“ค์–ด์˜ค๋ฉด ๋ฐ›๊ฒ ๋‹ค๋ผ๋Š” ์˜๋ฏธ์—์š”.


๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ
NGINX ๋ฌธ๋ฒ• ๊ฒ€์‚ฌ ์š”๋ น

1. nginx -t ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด nginx ์„ค์ • ํŒŒ์ผ ์•ˆ์— Script๋ฌธ์ด ๋ฌธ๋ฒ•์— ๋งž๊ฒŒ ์ž‘์„ฑ ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ ๊ฐ€๋Šฅ.

์ถœ์ฒ˜ : https://www.youtube.com/watch?v=hA0cxENGBQQ


์ถœ์ฒ˜ : https://www.youtube.com/watch?v=hA0cxENGBQQ

 

 

 

 

        ๐Ÿ“ฆ Http Block์ด๋ž€?

1. http Protocol ์‚ฌ์šฉ

์ถœ์ฒ˜ : https://www.youtube.com/watch?v=hA0cxENGBQQ


์œ„์—์„œ Script File์€ Server Block ๋ฐ–์— ์—†์—ˆ์ง€๋งŒ, nginx.conf File์„ ๋ณด๊ฒŒ ๋˜๋ฉด http {}๋กœ http Block์ด ์žˆ๊ณ , ๊ทธ ์•ˆ์— include๋ฅผ ํ•˜์—ฌ ๋‹ค๋ฅธ conf File์„ ํฌํ•จํ•˜๊ฒŒ ๋˜์–ด ์žˆ์–ด์š”.

๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— http Block์„ ์ƒ๋žตํ•˜๋”๋ผ๋„ ์ด๋ฏธ ์ „์—ญ์ ์œผ๋กœ ํฌํ•จ์ด ๋˜์–ด ์žˆ๋‹ค๋Š” ์˜๋ฏธ๊ฐ€ ๋˜์š”.





        ๐Ÿ“ฆ Location Block์ด๋ž€?

1. ์š”์ฒญ URI๋ฅผ ๋ถ„์„ํ•˜์—ฌ ์„ธ๋ถ€ ์„ค์ •

์ถœ์ฒ˜ : https://www.youtube.com/watch?v=hA0cxENGBQQ


์œ„์˜ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด /(root)์™€ /documents, /images์— ๋Œ€ํ•œ URI๋ฅผ ๋”ฐ๋กœ ์„ค์ •ํ•˜๊ณ , ๊ฐ๊ฐ์˜ URI๊ฐ€ ํ˜ธ์ถœ ๋˜์—ˆ์„ ๋•Œ, ์–ด๋–ค ์ฒ˜๋ฆฌ๋ฅผ ํ•  ๊ฒƒ์ธ์ง€๋ฅผ ์ •ํ•  ์ˆ˜ ์žˆ์–ด์š”.

Server Block ์•ˆ์— Location Block์„ ๋„ฃ๊ณ , ๊ฑฐ๊ธฐ์„œ URI ๋ณ„ ์„ค์ •์„ ํ•˜๋ฉด ๋˜์š”.


์ถœ์ฒ˜ : https://www.youtube.com/watch?v=hA0cxENGBQQ


์œ„์™€ ๊ฐ™์ด ๊ฐ๊ฐ์˜ URI๋ฅผ ํ˜ธ์ถœํ–ˆ์„ ๋•Œ, ํŠน์ • ๋ฌธ์ž์—ด์ด ๋ฐ˜ํ™˜๋˜๋„๋ก ํ•  ์ˆ˜ ์žˆ์–ด์š”.

์ถœ์ฒ˜ : https://www.youtube.com/watch?v=hA0cxENGBQQ


์œ„์™€ ๊ฐ™์ด HTTP Status Code์™€ ํ•จ๊ป˜ ๋ฌธ์ž์—ด์ด ๋ฐ˜ํ™˜๋˜๋„๋ก ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์ฃผ์—ˆ์–ด์š”.

ํ•˜์ง€๋งŒ, ์œ„์™€ ๊ฐ™์ด ์„ค์ •ํ•˜๊ฒŒ ๋˜๋ฉด ํ•œ ๊ฐ€์ง€ ๋ฌธ์ œ์ ์ด ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ์ด์—์š”.


์˜ˆ๋ฅผ ๋“ค์–ด /a/aaa ๋ผ๋Š” ํ•˜์œ„ URI ์ถ”๊ฐ€๋กœ ์žˆ์–ด ์ด์— ๋Œ€ํ•œ ์„ค์ •์„ ํ•˜๋”๋ผ๋„ /a์— ๋Œ€ํ•œ ์„ค์ •์ด ๋จน์–ด๋ฒ„๋ ค ์›ํ•˜๋Š” ์ž‘์—…์ด ์ฒ˜๋ฆฌ๋˜์ง€ ์•Š๋Š” ๋ฌธ์ œ์—์š”.

์ฆ‰, Prefix๋งŒ ๋งž๊ฒŒ ๋˜๋ฉด ๋’ค์— ์ถ”๊ฐ€ URI ๋ฌธ์ž์—ด์ด ์žˆ๋”๋ผ๋„ ํ•ด๋‹น Prefix์— ์„ค์ •ํ•œ ์ž‘์—…์ด ์ง„ํ–‰๋˜๊ฒŒ ๋œ๋‹ค๋Š” ๊ฒƒ์ด์—์š”.

์ถœ์ฒ˜ : http://nginx.org/en/docs/beginners_guide.html


์œ„ ๋‚ด์šฉ์€ NGINX ๊ณต์‹ ๋ฌธ์„œ์—๋„ ์–ธ๊ธ‰์ด ๋˜์–ด ์žˆ์–ด์š”.

์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” Prefix Match๊ฐ€ ์•„๋‹Œ Exact Match ๋ฐฉ์‹์œผ๋กœ ๋ณ€๊ฒฝ์„ ํ•ด์ฃผ์–ด์•ผ ํ•ด์š”.


์ถœ์ฒ˜ : http://nginx.org/en/docs/beginners_guide.html


์ฆ‰, ์กฐ๊ฑด ๊ฒ€์‚ฌ๋ฅผ ํ•˜๋Š” ๋ถ€๋ถ„์ด ์ถ”๊ฐ€๋˜์–ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์ด์—์š”.

์ถœ์ฒ˜ : https://www.youtube.com/watch?v=hA0cxENGBQQ


์œ„์™€ ๊ฐ™์ด URI๋ฅผ ์„ค์ •ํ•˜๋Š” location Block์— '='์„ ๋ถ™ํ˜€์ฃผ๋ฉด ํ•ด๊ฒฐ ๋œ๋‹ต๋‹ˆ๋‹ค.
์ด๊ฑด ๊ทธ๋ƒฅ ๊ธฐ๋ณธ์ ์œผ๋กœ ์จ์•ผ ํ•  ๊ฒƒ ๊ฐ™์•„์š”.







        ๐Ÿ“ฆ File Return

1. ๋ฌธ์ž์—ด์ด ์•„๋‹Œ File์„ ๋ฐ˜ํ™˜(html, png, ๋“ฑ)

์ถœ์ฒ˜ : https://www.youtube.com/watch?v=hA0cxENGBQQ


์œ„์—์„œ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•  ๋•Œ์™€ ์ฐจ์ด์ ์€ root ๋””๋ ‰ํ‹ฐ๋ธŒ๋ฅผ ์ด์šฉํ•ด์„œ ๋ฐ˜ํ™˜ํ•˜๊ณ ์ž ํ•˜๋Š” File์ด ์œ„์น˜ํ•œ ๊ฒฝ๋กœ๋ฅผ ์ ์–ด์ค˜์•ผ ํ•˜๋Š” ๊ฒƒ์ด์—์š”.

ํ•ด๋‹น ๊ฒฝ๋กœ์— File์ด ์žˆ๋‹ค๋ฉด ๊ทธ File์„ ๋ฐ˜ํ™˜ํ•˜๊ฒŒ ๋˜๊ณ , ๋งŒ์•ฝ File์ด ์—†๋‹ค๋ฉด NGINX ์„ค์ •์— ๋”ฐ๋ฅธ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๊ฒŒ ๋˜๋Š”๋ฐ, ๋Œ€ํ‘œ์ ์œผ๋กœ 404 Not Found Error๋ฅผ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ์–ด์š”.

ํ˜„์žฌ /tmp/images ๋ผ๋Š” Directory๊ฐ€ ์žˆ๊ณ , ๊ทธ ์•ˆ์— a๋ผ๋Š” File์ด ๋“ค์–ด๊ฐ€๊ฒŒ ์„ค์ •์ด ๋˜์–ด ์žˆ์–ด์š”.

์ด ๋•Œ, NGINX ์„ค์ • File์—๋Š” Prefix URI์ธ /tmp๋ฅผ root ๋””๋ ‰ํ‹ฐ๋ธŒ์— ์ ์–ด์ฃผ๊ณ , ํ•˜์œ„ ์œ„์น˜๊ฐ’์„ location ๋””๋ ‰ํ‹ฐ๋ธŒ์— ์ ์–ด์ค˜์•ผํ•ด์š”.

# case1 : ์ •๊ทœ์‹(๋Œ€์†Œ๋ฌธ ๊ตฌ๋ถ„ ํ•˜์ง€ ์•Š์Œ)
# ์ค€๋น„ :
mkdir -p /tmp/images
touch /tmp/images/a.jpg
curl helloword.com:82/images/a.jpg
curl helloworld.com:82/a.jpg

 

server {
	listen *:82;
    
    location = / {
    	return 200 "helloworld";
    }
        
    location /images {
    	root /tmp;
        try_files $uri = 404;
    }
}

 

 

 

        ๐Ÿ“ฆ Reverse Proxy๋ž€?

Proxy๋ฅผ ๋จผ์ € ๊ฐ„๋‹จํ•˜๊ฒŒ ์ด์•ผ๊ธฐํ•˜์ž๋ฉด A, B, C๋ผ๋Š” ์‚ฌ๋žŒ์ด ์žˆ๋Š”๋ฐ, A์™€ C๊ฐ€ ์‹ธ์šด๊ฑฐ์—์š”.
๋‘˜์€ ํ™”ํ•ด๋Š” ํ•˜๊ณ  ์‹ถ์ง€๋งŒ, ์ž์กด์‹ฌ์ด ๊ฐ•ํ•ด์„œ ์ง์ ‘ ์ด์•ผ๊ธฐ ํ•˜๊ณ  ์‹ถ์ง€๋Š” ์•Š์•˜์–ด์š”.

A๋Š” B์—๊ฒŒ ์ด๋ ‡๊ฒŒ ๋งํ–ˆ์–ด์š”. "Cํ•œํ…Œ ๋ฐฐ๊ณ ํ”ˆ๋ฐ, ๋ฐฐ ์•ˆ ๊ณ ํ”„๋ƒ๊ณ  ๋ฌผ์–ด๋ด์ค˜"
B๋Š” C์—๊ฒŒ ์ „๋‹ฌ์„ ํ–ˆ์–ด์š”.

๊ทธ๋Ÿฌ์ž C๊ฐ€ B์—๊ฒŒ "๋ฐฐ ๊ณ ํ”ˆ๋ฐ, ๋ญ ๋จน์„๊ฑด์ง€ A์—๊ฒŒ ๋ฌผ์–ด๋ด์ค˜"๋ผ๊ณ  ์ด์•ผ๊ธฐ ํ–ˆ์–ด์š”.
B๋Š” A์—๊ฒŒ ์ „๋‹ฌ ํ–ˆ์–ด์š”.

์ด ๋•Œ, B๊ฐ€ ๋ฐ”๋กœ Proxy ์—ญํ• ์„ ํ•ด ์ค€ ๊ฒƒ์ด๊ณ , ์ค‘๊ณ„ Server๋ฅผ Proxy Server๋ผ๊ณ  ํ•ด์š”.

Proxy์—๋Š” ํฌ๊ฒŒ ๋‘๊ฐ€์ง€๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ์–ด์š”.

1. Forward Proxy (์ˆœ๋ฐฉํ–ฅ ํ”„๋ก์‹œ)

ํšŒ์‚ฌ์˜ ๋‚ด๋ถ€๋ง์— ๋ฌผ๋ ค ์žˆ๋Š” PC๋‚˜, Server๋“ค์ด ์ธํ„ฐ๋„ท์— ์ ‘์†ํ•  ๋•Œ, ๊ฐ€์žฅ ๋จผ์ € Proxy Server๋ฅผ ๊ฑฐ์นœ ๋’ค ์ธํ„ฐ๋„ท์œผ๋กœ ๋‚˜๊ฐ€๊ฒŒ ๋˜๋Š” ์—ฐ๊ฒฐ ๋ฐฉ์‹์„ ์ด์•ผ๊ธฐํ•ด์š”.

์ˆœ๋ฐฉํ–ฅ ํ”„๋ก์‹œ๋Š” ๋‘๊ฐ€์ง€ ์žฅ์ ์ด ์กด์žฌํ•ด์š”.

  โˆ™ ๋ณด์•ˆ : Proxy Server์—์„œ In / Out Bound Packe์— ๋Œ€ํ•œ ๋ณด์•ˆ ์ •์ฑ… (Content Filering ๋“ฑ)์„ ์ ์šฉ.
  โˆ™ ์„ฑ๋Šฅ : Proxy Server๋Š” ๋‚ด๋ถ€์— Cache๋ฅผ ์œ ์ง€ํ•˜๋ฉฐ, ์ด๋ฏธ ํ•œ๋ฒˆ ํ†ต์‹ ํ•œ ์™ธ๋ถ€ Server์˜ Image, File, ๊ทธ ์™ธ ์ •๋ณด๋“ค์„
                 ์ €์žฅํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋‚ด๋ถ€ ์‚ฌ์šฉ์ž๊ฐ€ ์›๊ฒฉ ์„œ๋ฒ„ ์ ‘์† ์‹œ Cache์— Data๊ฐ€ ์žˆ์œผ๋ฉด ๋ฌผ๋ฆฌ์ ์œผ๋กœ ๋จผ ๊ณณ๊นŒ์ง€ ๊ฐˆ ํ•„์š”์—†์ด
                 Proxy Server๊ฐ€ Data๋ฅผ ์ œ๊ณตํ•˜์—ฌ ๋น ๋ฅธ ํ†ต์‹  ๊ฐ€๋Šฅ.

 

์ถœ์ฒ˜ : https://medium.com/sjk5766/nginx-reverse-proxy-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0-e11e18fcf843





2. Reverse Proxy (์—ญ๋ฐฉํ–ฅ ํ”„๋ก์‹œ)

ํšŒ์‚ฌ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํšŒ์‚ฌ ์™ธ๋ถ€์—์„œ ๋‚ด๋ถ€ Server๊ฐ€ ์ œ๊ณตํ•˜๋Š” Service ์ ‘๊ทผ์„ ํ•˜๋ ค ํ•  ๋•Œ, Proxy Server๋ฅผ ๋จผ์ € ๊ฑฐ์นœ ๋’ค ๋‚ด๋ถ€ Server๋กœ ๋“ค์–ด์˜ค๊ฒŒ ํ•˜๋Š” ๋ฐฉ์‹์ด์—์š”.


์—ญ๋ฐฉํ–ฅ ํ”„๋ก์‹œ๋ฅผ ์‚ฌ์šฉํ•จ์œผ๋กœ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ์žฅ์  ๋˜ํ•œ, ์„ธ ๊ฐ€์ง€๊ฐ€ ์žˆ์–ด์š”.


  โˆ™ ๋ณด์•ˆ : ์™ธ๋ถ€ ์ด์šฉ์ž๋Š” ์‹ค์ œ ๋‚ด๋ถ€๋ง์— ์žˆ๋Š” Server์— ์กด์žฌ๋ฅผ ์•Œ ์ˆ˜ ์—†์œผ๋ฉฐ, ๋ชจ๋“  ์ ‘์†์€ Reverse Proxy Server์—
     ๋“ค์–ด์˜ค๊ฒŒ ๋œ๋‹ค. Reverse Proxy๋Š” ์š”์ฒญ์— Mapping ๋˜๋Š” ๋‚ด๋ถ€ Server์˜ ์ •๋ณด๋ฅผ ์•Œ๊ณ  ์žˆ์œผ๋ฏ€๋กœ, ์™ธ๋ถ€์—์„œ ๋“ค์–ด์˜จ
     ์š”์ฒญ์„ ํ•ด๋‹น Server์—๊ฒŒ ์ „๋‹ฌํ•˜๊ฒŒ ๋œ๋‹ค. ๋”ฐ๋ผ์„œ ๋‚ด๋ถ€ Server์˜ ์ •๋ณด๋ฅผ ์™ธ๋ถ€๋กœ๋ถ€ํ„ฐ ์ˆจ๊ธธ ์ˆ˜ ์žˆ๋‹ค.

  โˆ™ ๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ : Proxy Server๊ฐ€ ๋‚ด๋ถ€ Server ์ •๋ณด๋ฅผ ์•Œ๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ์„ ํ†ตํ•ด ๋ถ€ํ•˜ ์—ฌ๋ถ€์— ๋”ฐ๋ผ ์š”์ฒญ
      ๋ถ„๋ฐฐํ•˜๋Š” ๋ถ€ํ•˜ ๋ถ„์‚ฐ์„ ํ•  ์ˆ˜ ์žˆ๋‹ค.

     - Scale Up : Server ์„ฑ๋Šฅ ๋†’์ด๊ธฐ (๋น„์šฉ๋„ ๋Œ€์นญ์œผ๋กœ ์˜ฌ๋ผ๊ฐ)
     - Scale Out : ์—ฌ๋Ÿฌ ๋Œ€์˜ Server๋ฅผ ๋‘์–ด ํŠธ๋ž˜ํ”ฝ ๋ถ„์‚ฐ (๋ฌผ๋ฆฌ / ๋…ผ๋ฆฌ์ ์œผ๋กœ)

  โˆ™ ์„ฑ๋Šฅ : Proxy Server๊ฐ€ Cache ๊ธฐ๋Šฅ๊ณผ ํŠธ๋ž˜ํ”ฝ ๋ถ„์‚ฐ ๊ธฐ๋Šฅ์„ ๊ฒฐํ•ฉ์‹œ์ผœ ์ „๋ฐ˜์ ์ธ Server ์„ฑ๋Šฅ ํ–ฅ์ƒ์„ ์ด๋Œ ์ˆ˜ ์žˆ๋‹ค.

์ถœ์ฒ˜ : https://medium.com/sjk5766/nginx-reverse-proxy-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0-e11e18fcf843





 

 

        ๐Ÿ“ฆ Load Balancing์ด๋ž€?

Service ์ค‘์ธ Server๊ฐ€ ๊ฐ‘์ž๊ธฐ ์ฃฝ๊ฑฐ๋‚˜, Network ์žฅ์• ๋“ฑ Service๋ฅผ ํ•  ์ˆ˜ ์—†๋Š” ์ƒํ™ฉ์ด ์ƒ๊ฒจ ๋ฒ„๋ฆฐ๋‹ค๋ฉด 1๋Œ€์˜ Server๋กœ๋งŒ ์šด์˜์ค‘์ผ ๋•Œ, ํ•ด๋‹น Service๋Š” ์šด์˜ ๋ถˆ๊ฐ€ ์ƒํƒœ๋ฅผ ๋งž์ดํ•˜๊ฒŒ ๋˜์š”.

์ด๋ฅผ ๋ง‰๊ธฐ ์œ„ํ•ด ์—ฌ๋Ÿฌ๋Œ€์˜ Server๋ฅผ Master / Slave ํ˜น์€ Master / Master ๋“ฑ์œผ๋กœ ๊ตฌ์„ฑํ•˜๊ณ , ์žฅ์•  ๋Œ€๋น„๋ฅผ ํ•ด๋‘๊ฒŒ ๋˜๋Š”๋ฐ,
์ด๋ฅผ Fail Over ์ฆ‰, ์žฅ์•  ๋Œ€๋น„๋ผ๊ณ  ํ•ด์š”.

ํ•˜๋“œ์›จ์–ด์ ์œผ๋กœ ๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ์„ ํ•  ์ˆ˜๋„ ์žˆ๋Š”๋ฐ, ๋Œ€์ฒด๋กœ L4 Switch๋ผ๋Š” ์žฅ๋น„๋ฅผ ์ด์šฉํ•ด์„œ ๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ์„ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์–ด์š”.


์ถœ์ฒ˜ : https://velog.io/@kimjiwonpg98/Nginx-%EB%A1%9C%EB%93%9C%EB%B0%B8%EB%9F%B0%EC%8B%B1-%EA%B0%9C%EB%85%90-%EB%B0%8F-%EA%B5%AC%EC%B6%95


1. OSI 7 Layer์˜ Network Layer (4๊ณ„์ธต) ์œ„์น˜.
2. TCP / UDP Port ์ •๋ณด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ Network ํ†ต์‹ .
3. Data ์•ˆ์„ ๋ณด์ง€ ์•Š๊ณ , Packet Level์—์„œ ์ž‘์—….
   โˆ™ ์†๋„๊ฐ€ ๋น ๋ฅด๊ณ , ํšจ์œจ์ด ๋†’๋‹ค.
   โˆ™ Data ๋‚ด์šฉ์„ ๋ถ€ํ˜ธํ™”ํ•˜์ง€ ์•Š์•„ ์•ˆ์ „.
   โˆ™ L7 Switch ๋ณด๋‹ค ์ €๋ ด.
4. ์‚ฌ์šฉ์ž IP๊ฐ€ ์ˆ˜์‹œ๋กœ ๋ฐ”๋€Œ๋Š” ๊ฒฝ์šฐ ์—ฐ์†์  Service ์ œ๊ณต ์–ด๋ ต๋‹ค.


L7 Switch๋กœ๋„ ๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ์„ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์–ด์š”.

์ถœ์ฒ˜ : https://velog.io/@kimjiwonpg98/Nginx-%EB%A1%9C%EB%93%9C%EB%B0%B8%EB%9F%B0%EC%8B%B1-%EA%B0%9C%EB%85%90-%EB%B0%8F-%EA%B5%AC%EC%B6%95


1. OSI 7 Layer์˜ Network Layer (7๊ณ„์ธต) ์œ„์น˜.
2. TCP / UDP์™€ HTTP URI, FTP File Name, Cookie ์ •๋ณด ๋“ฑ์„ ๋ฐ”ํƒ•์œผ๋กœ ์ž‘์—….

3. Caching ๊ธฐ๋Šฅ ์ œ๊ณต.
4. ์„ฌ์„ธํ•œ Routing ๊ฐ€๋Šฅ.
5. ๋น„ ์ •์ƒ์  ํŠธ๋ž˜ํ”ฝ ์‚ฌ์ „ Filtering (์•ˆ์ „์„ฑ ํ–ฅ์ƒ)
6. ๋„ˆ๋ฌด๋„ˆ๋ฌด ๋น„์‹ธ๋‹ค.


๊ทธ๋Ÿผ ์ด์ œ ์šฐ๋ฆฌ๊ฐ€ ์จ๋ณด๋ ค๊ณ  ํ•˜๋Š” Software ๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ์— ๋Œ€ํ•ด ์•Œ์•„๋ณผ๊ฒŒ์š”.

์†Œํ”„ํŠธ์›จ์–ด ๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ์€ ๊ธฐ๋ณธ์ ์œผ๋กœ Reverse Proxy ๊ธฐ๋ฐ˜์œผ๋กœ ๋™์ž‘ํ•ด์š”.

์ด๋Š” ๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ๋งŒ์„ ์œ„ํ•ด ๊ฐœ๋ฐœ๋œ ํ”„๋กœ๊ทธ๋žจ์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ธฐ๋ณธ์ ์ธ ๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ์˜ ๊ธฐ๋Šฅ๋งŒ์ด ์žˆ์ง€๋งŒ, ๊ทธ๋งŒํผ ๋น„์šฉ์ด ์ €๋ ดํ•˜๊ณ , ๊ตฌ์ถ•์ด ์‰ฝ๋‹ค๋Š” ์žฅ์ ์„ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์š”.

์†Œํ”„ํŠธ์›จ์–ด ๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ์„ ํ•  ์ˆ˜ ์žˆ๋Š” ์†Œํ”„ํŠธ ์›จ์–ด๋Š” ๋Œ€ํ‘œ์ ์œผ๋กœ ๋‘ ๊ฐ€์ง€๊ฐ€ ์žˆ์–ด์š”.

1. NGINX
   โˆ™ Open Source.
   โˆ™ ํŠน์ • ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ NGINX Plus์—์„œ๋งŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅ.

2. HA Proxy
   โˆ™ Open Source.
   โˆ™ ์—ฌ๋Ÿฌ ๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ ๊ธฐ๋Šฅ ์ง€์›.


์ด๋Ÿฌํ•œ ์  ๋•Œ๋ฌธ์— NGINX๋ฅผ ์‚ฌ์šฉํ•œ๋‹ต๋‹ˆ๋‹ค.




 

   

 

 

728x90
๋ฐ˜์‘ํ˜•