nginx uWSGI Django python运行环境安装和配置
uWSGI is a fast (pure C), self-healing, developer/sysadmin-friendly application container server.”, it utilizes the uwsgi protocol (notice the all-lowercase spelling), and supports WSGI applications served from it.
上面这段文字是uWSGI的官方定义。
uWSGI是一个快速(纯C的)、自维护、对开发管理人员友好的应用容器。它使用uwsgi协议(小写定义),支持WSGI应用运行在它上面。
uwsgi安装
1 2 3 4 5 6 7 8 |
yum install python python-devel libxml2 libxml2-devel python-setuptools zlib-devel wget openssl-devel pcre pcre-devel sudo gcc make autoconf automake cd /usr/local/src/ wget http://projects.unbit.it/downloads/uwsgi-lts.tar.gz tar -zxvf uwsgi-lts.tar.gz cd uwsgi-1.4.10/ python2.4 setup.py build make |
或者查看这里有许多uwsgi安装方法http://uwsgi-docs.readthedocs.org/en/latest/Install.html
myapp.py 放到运行命令目录
1 2 3 |
def application(environ, start_response): start_response("200 OK", [("Content-Type", "text/plain")]) return ["Hello World!"] |
启动uwsgi
1 |
uwsgi -s 127.0.0.1:3031 -w myapp |
在浏览器内输入:http://127.0.0.1:3031,看是否有“Hello World”输出,若没有输出,请检查你的安装过程.
nginx配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
upstream app_server { server 127.0.0.1:3031; } server { listen 80; server_name example.com; location / { try_files $uri @proxy_to_app; } location @proxy_to_app { uwsgi_pass app_server; include uwsgi_params; } } |
浏览器访问
1 |
http://yourip |
未完待续...
这 - -!说好的nginx呢。。。 这么只有uWSGI