什麼是 WSGI? 什麼又是 gunicorn?

WSGI 介紹 WSGI (Python Web Server Gateway Interface) 是一種 協議 protocol,定義了 web server 和 python web application 或 framework 之間溝通的規範。 它的目的是讓不同的 Python Web Framework (如 Flask、Django) 與不同的 Web Server (如 Gunicorn、uWSGI) 可以互相兼容。 所以,WSGI web server 其實就是應用了 WSGI 的 Web server。 📌 運作方式: Client 發送 HTTP request(Web browser → Web server)。 Web server (e.g. gunicorn) 透過 WSGI 呼叫 Python applicatoin(e.g. Flask/Django)。 Python applicatoin 處理請求,並回傳 HTTP response。 Web server 再將 response 傳回給 web browser。 Gunicorn 介紹 Gunicorn (Green Unicorn) 是一種基於 unix 系統 的 WSGI HTTP server,專門用來執行 Python Web 應用程式 (如 Flask、Django) ,並提供高效能的並發處理。通常在 反向代理 (Nginx, Apache) 與 Web 應用程式 之間。 圖片來源: https://www.maxlist.xyz/2020/05/06/flask-wsgi-nginx/ ...

February 13, 2025 · Allen Hsieh