在 Ubuntu 14.x 搭建 Nginx Uwsgi Django 環境之(一):Uwsgi的安裝

對於 Python2.x 版本:

第一步:sudo apt-get install python-dev

第二步:sudo apt-get install python-pip
第三部:sudo pip install uwsgi


對於 Python3.x 版本:

第一步:sudo apt-get install python3-dev

第二步:sudo apt-get install python3-pip
第三部:sudo pip3 install uwsgi


測試是否安裝成功
1、在 /home/ubuntu/下面創建 test.py文件
# test.py

def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return ["Hello World"] #python2.x
    #return ["Hello World"] #python3.x

2、啓動服務: uwsgi --http-socket :8001 --plugin python --wsgi-file test.py

3、在瀏覽器輸入:localhost:8001, 出現提示 Hello World, 恭喜,安裝配置成功

另外,對於敲命令行這種形式太過麻煩, uwsgi還提供多種配置文件啓動方式,我偏向ini配置
我們在 /home/ubuntu/下面創建 uwsgi.ini 文件
[uwsgi]
http-socket =  :8001
chdir = /home/ubuntu/
#plugin = python
wsgi-file = test.py
#process = 2
#threads = 2
#stats = 127.0.0.1:8011

然後啓動的時候就很簡單:

uwsgi --ini /home/ubuntu/uwsgi.ini


-------------------------下面是安裝過程中踩過的坑,估計這個纔是更有用的東西 -----------

1、會自動下載安裝最新版本的uwsg,編譯時提示
[x86_64-linux-In file included from plugins/python/python_plugin.c:1:0:

plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or directory
 #include <Python.h>
 compilation terminated.
這個是因爲沒有安裝 python-dev包,sudo apt-get install python-dev 解決
2、Permission denied
collect2: error: ld returned 1 exit status
error linking uWSGI
運行pip的全新不夠,sudo apt-get install python-pip 解決

3、運行 uwsgi --http-socket :8001 --plugin python
提示  /usr/lib/uwsgi/plugins/python_plugin.so: cannot open shared object file: No such file or directory
sudo apt-get install uwsgi 安裝uwsgi沒有安裝這些plugin 的so文件,用 sudo pip install uwsgi 安裝 uwsgi來解決。
如果不用pip安裝,可能還需要 sudo apt-get install uwsgi-plugin-python 這來安裝plugin的so

4、直接運行pip提示沒有安裝pip時,需要用 sudo apt-get install python-pip 安裝一下pip

uwsgi --http-socket :8001 --plugin python --wsgi-file test.py
發佈了23 篇原創文章 · 獲贊 39 · 訪問量 24萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章