Backend
References
Nouns
Gateway Interface
Web App 與 Web Server 溝通的協議
-
CGI (Common Gateway Interface)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- Web 伺服器在收到 request 時,如果要將 request 交由其他程式(CGI program)處理,就需要建立 1 個新的 process 執行該程式
- 該程式處理完 request 之後,就必須將 response 輸出到 STDOUT,Web 伺服器就會把這個 STDOUT 回應給使用者。
- 如果這個外部程式需要接收資料,則可以透過讀取 STDIN 得到資料,如果是需要讀取 request 相關資料,則是透過讀取環境變數取得,這些環境變數會在 Web 伺服器建立新的 process 時一併建立好。
- 這種做法天生就無法處理大量 requests,這也是為什麼我們現在少使用 CGI 的緣故。
-
FastCGI (Fast Common Gateway Interface)
…
-
WSGI (Web Server Gateway Interface)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- Python 在 PEP333 提出。
- 協議分為兩端:Framework Side (Application Side) 和 Gateway Side (Server Side)
- 比如:Flask、Django 等 Web App 框架實作 Framework Side
- 比如:Gunicorn、uWSGI 等 Web Server 實作 Gateway Side
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 即便有了 uWSGI、Gunicorn 等 Web Server,還是會搭上 Nginx。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
ASGI (Asynchronous Server Gateway Interface)
- 協議分為兩端:Application 和 Protocol Server
- 比如:FastAPI 等 Web App 框架實作 Application
- 比如:Uvicorn、Hypercorn 等 Web Server 實作 Protocol Server
- 向下相容 (ASGI 相容 WSGI)
- 支援異步
- 支援 WebSockets、SSE 等 persistent connection (而非像 HTTP request 那樣短期的)
Web Server
Web Server 會實作 Gateway Interface 來橋接 Web App 和 HTTP requests 之間的溝通。
Type |
Example |
all |
Nginx, Apache2, Lighttpd |
Python |
uWSGI, Gunicorn, Uvicorn, Hypercorn |
Java |
Tomcat |
PHP |
PHP-FPM |
Forward Proxy (正向代理)
Reverse Proxy (反向代理)