ํ’€์Šคํƒ ์›น๐ŸŒ ๊ฐœ๋ฐœ์ž ์ง€๋ง์ƒ ๐Ÿง‘๐Ÿฝโ€๐Ÿ’ป
โž• ์ธ๊ณต์ง€๋Šฅ ๊ด€์‹ฌ ๐Ÿค–


Categories


Recent views

  • 1
  • 2
  • 3
  • 4
  • 5

Django WSGI ๊ธฐ๋ณธ

WSGI(Web Server Gateway Interface)

WSGI๋ž€?

Django ๊ฐ™์€ Python ๊ณ„์—ด ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„œ๋ฒ„์—์„œ ์›น ์„œ๋ฒ„์™€ ํ†ต์‹ ํ•  ๋•Œ, ๋ฏธ๋“ค์›จ์–ด๋กœ ์ž‘์šฉํ•˜๋ฉฐ,

  • ์›น์„œ๋ฒ„์™€ ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„œ๋ฒ„์˜ ํ˜ธํ™˜์„ฑ ๊ด€๊ณ„์—†์ด ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๊ณ ,

  • ์—ฌ๋Ÿฌ ์›Œ์ปค๋ฅผ ํ†ตํ•ด ์š”์ฒญ์„ ๋™๊ธฐ์ , ํ˜น์€ ๋น„๋™๊ธฐ์ ์œผ๋กœ ๋น ๋ฅด๊ฒŒ ์ฒ˜๋ฆฌํ•˜๊ฒŒ ๋„์™€์ค€๋‹ค.

  • ํŠนํžˆ Python์œผ๋กœ ๋Œ์•„๊ฐ€๋Š” ์„œ๋ฒ„์˜ ๊ฒฝ์šฐ python ์ฝ”๋“œ๋ฅผ ๋ถˆ๋Ÿฌ์™€ ๋กœ๋”ฉํ•˜๋Š”๋ฐ ๋งŽ์€ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฌ๋Š”๋ฐ, ์ด๋ฅผ ํ”„๋ฆฌ ํฌํ‚น(pre-forking)๋ฅผ ํ†ตํ•ด ๋ฏธ๋ฆฌ ๋ถˆ๋Ÿฌ์˜ค๊ณ  ๊ณต์œ ํ•˜์—ฌ ์„ฑ๋Šฅ์„ ํ–ฅ์ƒ์‹œํ‚จ๋‹ค.

  • ํ™•์žฅ๋œ ๊ธฐ๋Šฅ์œผ๋กœ Nginx์™€ ๊ฐ™์€ ์›น์„œ๋ฒ„์™€ ๊ฐ™์€ ์—ญํ• ์„ ๋งก๊ธฐ๋„ ํ•œ๋‹ค.

Gunicorn๊ณผ uWSGI๊ฐ€ ์กด์žฌํ•˜๋ฉฐ, ์ถ”๊ฐ€๋กœ ๋น„๋™๊ธฐ์  ์ฒ˜๋ฆฌ๋ฅผ ์ง€์›ํ•˜๋Š” ASGI(Asynchronous Server Gateway Interface)๊ฐ€ ์กด์žฌํ•œ๋‹ค.

Setting up Django and your web server with uWSGI and nginx ์ฐธ์กฐ

uwsgi ์˜ˆ์ œ

pip install uwsgi

์œ„ ์ฝ”๋“œ๋ฅผ ์ด์šฉํ•ด virutalenv ์„ค์ • ํ›„ ๋‹ค์šด๋กœ๋“œํ•œ ํ›„ ์•„๋ž˜์™€ ๊ฐ™์ด uwsgi.ini ์„ค์ • ํŒŒ์ผ์„ ๋งŒ๋“ ๋‹ค.

[uwsgi]
socket = /srv/docker-server/movie_backend.sock 
// ์ƒ์„ฑํ•  ์†Œ์ผ“ํŒŒ์ผ ์œ„์น˜ ๋˜๋„๋ก์ด๋ฉด ์ ˆ๋Œ€ ์œ„์น˜ ๊ธฐ์ž…
master = true 
// ๋งˆ์Šคํ„ฐ ์„œ๋ฒ„์ธ๊ฐ€?
processes = 1
threads = 2

chdir = /srv/docker-server/
// ํ”„๋กœ์ ํŠธ ์œ„์น˜
module = movie_backend.wsgi
// django์˜ wsgi ์—ฐ๊ฒฐ ๋ชจ๋“ˆ ์œ„์น˜
logto = /var/log/uwsgi/uwsgi.log
// ๋กœ๊น… ์žฅ์†Œ
log-reopen = true 

vaccum = true
// ์ข…๋ฃŒ ์‹œ ๊ด€๋ จํ•œ ์ƒ์„ฑ ํŒŒ์ผ ์‚ญ์ œ

  • ๊ธฐํƒ€ ์ถ”๊ฐ€์ ์ธ ์„ค์ •์€ Configuring uWSGI โ€” uWSGI 2.0 documentation ํ™•์ธ

์œ„ uwsgi.iniํŒŒ์ผ์˜ ์ฃผ์„์„ ์ „๋ถ€ ์ง€์šฐ๊ณ  ํ”„๋กœ์ ํŠธ ํด๋”์— ๋„ฃ๋Š”๋‹ค.

uwsgi --ini uwsgi.ini

.ini์˜ ํŒŒ์ผ ๊ฒฝ๋กœ๋ฅผ ์ œ๋Œ€๋กœ ์„ค์ •ํ•˜์ž.

Attaching to django, nginx
django  | [uWSGI] getting INI configuration from uwsgi.ini

django์™€ ์ œ๋Œ€๋กœ ์—ฐ๊ฒฐ๋˜์—ˆ๋‹ค๋ฉด ์ƒ๋‹จ๊ณผ ๊ฐ™์€ ๋ฉ”์‹œ์ง€๊ฐ€ ๋‚˜ํƒ€๋‚˜๊ฒŒ ๋œ๋‹ค.