基于python的web项目,常见的部署方法有:
不过还有个uwsgi,它既不用wsgi协议也不用fcgi协议,而是自创了一个uwsgi的协议,据作者说该协议大约是fcgi协议的10倍那么快。uWSGI的主要特点如下: 环境ubuntu 12.04 IP:10.1.6.79 安装nginx
apt-get install nginx-full nginx-common nginx配置/etc/nginx/sites-enabled/example
server { listen 80; server_name 10.1.6.79; access_log /var/log/nginx/example_access.log; error_log /var/log/nginx/example_error.log; root /var/www/example; location / { uwsgi_pass 127.0.0.1:9001; include uwsgi_params; uwsgi_param UWSGI_SCHEME $scheme; uwsgi_param SERVER_SOFTWARE nginx/$nginx_version; } }安装uwsgi
apt-get install uwsgi uwsgi-plugin-python 如果你想安装所有的uwsgi插件,则可以安装uwsgi-plugin-all软件包 uwsgi配置/etc/uwsgi/apps-enabled/default.xml
<uwsgi> <plugin>python</plugin> <socket>127.0.0.1:9001</socket> <pythonpath>/var/www/example/app/</pythonpath> <app mountpoint="/"> <script>wsgi_configuration_module</script> </app> <master/> <processes>4</processes> <reload-mercy>8</reload-mercy> <cpu-affinity>1</cpu-affinity> <max-requests>2000</max-requests> <limit-as>512</limit-as> <reload-on-as>256</reload-on-as> <reload-on-rss>192</reload-on-rss> <no-orphans/> <vacuum/> </uwsgi> uwsgi配置文件中的参数也可以在命令行通过uwsgi指定,配置文件除了xml格式外,还可以写成ini格式的,软件包安装完毕后在/usr/share/doc/uwsgi/examples/conffile目录下会有一些xml和ini格式配置文件的例子。 wsgi_configuration_module.py脚本内容
#!/usr/bin/python import os import sys sys.path.append('/var/www/example/app') os.environ['PYTHON_EGG_CACHE'] = '/var/www/example/.python-egg' def application(environ, start_response): status = '200 OK' output = 'Hello World!' response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output]启动uwsgi
uwsgi -x /etc/uwsgi/apps-enabled/default.xml --daemonize /var/log/uwsgi/app/default.log
uwsgi 的参数: 除了直接用uwsgi命令启动外,还可以用init.d下的脚本启动, 不过需先修 改/etc/default/u wsgi中默认配置文件的路径,然后通过/etc/init.d/uwsgi start启动
#INHERITED_CONFIG=/usr/share/uwsgi/conf/default.ini INHERITED_CONFIG=/etc/uwsgi/apps-enabled/default.xml启动nginx
/etc/init.d/nginx start效果如下:
python在国内用来做web还不多,虽然python也有一些web框架,不过目前来看文档缺失、本身系统的稳定都还没经过量和时间的考验,要像PHP那样大规模的火起来还需一段时间。
nginx配置参考:http://wiki.nginx.org/HttpUwsgiModule#uwsgi_param uwsgi安装参考:http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html uwsgi配置参考:http://uwsgi-docs.readthedocs.org/en/latest/Options.html#vacuum (责任编辑:IT) |