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

来源:互联网 发布:php技术文章 编辑:程序博客网 时间:2024/06/06 00:48

对于 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
1 0
原创粉丝点击