Apache mod_wsgi模組簡介
Apache HTTP伺服器的mod_wsgi擴充套件模組,實現了Python WSGI標準,可以支援任何相容Python WSGI標準的Python應用。
出於安全的考慮,建議使用mod_wsgi 3.5及以後的版本,最新版本是2017年1月釋出的4.5.14。
1. WSGI(Web Server Gateway Interface)是一個統一的Python介面標準(PEP 3333),該標準描述了Python應用如何與Web伺服器通訊,多個Python應用之間如何級聯以處理請求。WSGI的實現位於Python應用和Web伺服器之間,從而支援將相容的Python應用無縫部署到任何Web伺服器上。
2. Apache伺服器對Python WSGI應用的執行模式
1)embedded模式
在Apache的子程序中執行Python WSGI應用。這樣,Python WSGI應用將與Apache上的其他應用共享程序。
執行效能高,但需要調整Apache MPM設定。
2)daemon模式(推薦)
Apache啟動專用程序執行Python WSGI應用,但是Python WSGI應用需要提供程序監控或WSGI介面卡。
執行更安全。
3. mod_wsgi擴充套件模組的安裝
1)建議安裝環境
- Python 2.6或Python 3.3以後版本
- Apache 2.4以後版本
2)作為Apache的一個擴充套件模組,以原始碼安裝到Apache伺服器
- wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.5.14.tar.gz
- tar xvfz mod_wsgi-4.5.14.tar.gz
- ./configure
- make
- make install
- LoadModule wsgi_module modules/mod_wsgi.so
- service httpd restart
3)作為Python安裝包,以原始碼安裝到Python的虛擬環境
- wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.5.14.tar.gz
- tar xvfz mod_wsgi-4.5.14.tar.gz
- python setup.py install
4)作為Python安裝包,從PyPI線上安裝到Python的虛擬環境
- pip install mod_wsgi
4.驗證安裝
利用mod_wsgi-express命令列工具,啟動Apache伺服器和mod_wsgi擴充套件模組,無需任何配置。
- mod_wsgi-express start-server
參考文獻:
舊官網https://code.google.com/archive/p/modwsgi/
新官網http://modwsgi.readthedocs.io/en/develop/
原始碼https://github.com/GrahamDumpleton/mod_wsgi
WSGI標準http://wsgi.readthedocs.io/en/latest/