對於 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