issues
search
yeomko22
/
TIL
Today I learned
1
stars
0
forks
source link
wsgi for web developer
#95
Open
yeomko22
opened
2 years ago
yeomko22
commented
2 years ago
Reference
https://www.youtube.com/watch?v=WqrCnVAkLIo
Follow the requests
django로 된 app application server를 실행시키려면 아래와 같은 명령어를 사용한다.
$ gunicorn --workers=2 mydjangoapp.wsgi
즉, gunicorn과 django app을 연결해주는 것은 wsgi이다.
그런데 wsgi란 무엇일까?
wsgi
PEP 333(3)에서 규정이 되어 있다.
웹 서버와 python web application applications or frameworks 사이의 표준 인터페이스를 제공한다.
이를 통해 web application portability across a variety of web servers 를 높여준다.
여기서의 web server는 apache, nginx 등의 솔루션을 말한다.
즉 앞단에 어떤 web server를 두더라도 wsgi 서버를 중간에 두면 뒷 단에 web applicaiton 서버와 효환이 된다!
static web severs
서버에 저장된 정적인 파일들을 서빙해준다. 이 떄 캐시 등을 활용한다.
그러나 이는 정적 파일만 해당한다.
Common Gateway Interface
dyanmic content를 제공하기 위해서 탄생한 것이 CGI이다.
그러나 이는 매 request마다 restart를 해주어야하는 단점이 있었다.
WSGI
fast, dynamic, pythonic한 방식을 원했다!
Gunicorn
PEP 3333 wsgi의 구현체이다.
django, flask, bottle과 같은 프레임워크들은 wsgi-compliant web app이다.
gunicorn은 wsgi-compliant web-app 들을 동작시킬 수 있는 wsgi server이다.
gunicorn은 pre-fork worker 모델을 사용한다.
yeomko22
commented
2 years ago
Rebuilding
즉 소켓을 이용하면 내 방식대로 web application server를 만들 수 있다.
그러나 이는 wsgi를 만족하지 않아서 이식성이 떨어진다.
wsgi는 request로 들어온 데이터를 wsgi에 맞는 환경변수로 바꿔주고, 이 환경변수를 애플리케이션 단에 넘겨주도록 한다.
Reference
Follow the requests
wsgi
static web severs
Common Gateway Interface
WSGI
Gunicorn