這篇文章主要講解了Django+Uwsgi+Nginx實現(xiàn)生產(chǎn)環(huán)境部署的方式,內(nèi)容清晰明了,對此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會有幫助。
如何在生產(chǎn)上部署Django
Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比較常見的一種方式。
uwsgi介紹
uWSGI是一個Web服務(wù)器,它實現(xiàn)了WSGI協(xié)議、uwsgi、http等協(xié)議。Nginx中HttpUwsgiModule的作用是與uWSGI服務(wù)器進行交換。
要注意 WSGI / uwsgi / uWSGI 這三個概念的區(qū)分。
uwsgi性能非常高
uWSGI的主要特點如下
總而言之uwgi是個部署用的好東東,正如uWSGI作者所吹噓的:
If you are searching for a simple wsgi-only server, uWSGI is not for you, but if you are building a real (production-ready) app that need to be rock-solid, fast and easy to distribute/optimize for various load-average, you will pathetically and morbidly fall in love (we hope) with uWSGI.
Uwsgi 安裝使用
# Install the latest stable release:
pip install uwsgi
# ... or if you want to install the latest LTS (long term support) release,
pip install https://projects.unbit.it/downloads/uwsgi-lts.tar.gz
基本測試
Create a file called test.py:
# test.py def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [b"Hello World"] # python3 #return ["Hello World"] # python2