1.环境配置
1)所需环境
操作系统 Mac os
python3.6,web.py 0.40, uWSGI 2.0.15, uwsgitop 0.10, nginx 1.10.3
2)步骤
安装python3.6 —略
安装web.py
easy_install web.py(推荐)
pip install web.py
如果报错 可能还需安装utils db
pip install utils
pip install db
安装uWSGI
pip install uwsgi
安装uwsgitop
uwsgitop作用:监测uwsgi运行状态
pip install uwsgitop
安装nginx
pip install nginx
2.编写python web应用app.py
1)代码
# coding:utf-8 import web urls = (‘/‘, ‘index‘) app = web.application(urls, globals()) class index: def GET(self): greeting="hello world" return greeting application = app.wsgifunc() if __name__ == "__main__": pass
2)注意
application = app.wsgifunc()必不可少,它作为wsgi或uwsgi操作的handler,uwsgi不会运行__main__中的代码
3.配置uwsgi
1)编写app.ini文件
[uwsgi] socket = /Users/cityking/workspace/django/uwsgi/uwsgi.sock wsgi-file = app.py home = /Users/cityking/workspace/django/django_env/ master = true
注意
确保是在app.py所在的文件目录
socket确保与nginx配置中的uwsgi_pass一样,/Users/cityking/workspace/django/uwsgi/为当前所在目录
Home是运行环境所在的目录
2)启动uwsgi
uwsgi app.ini
4.配置nginx
1)修改/usr/local/etc/nginx/nginx.conf文件
server { listen 8080; server_name localhost; location / { include uwsgi_params; uwsgi_pass unix:/Users/cityking/workspace/django/uwsgi/uwsgi.sock; } }
Listen为监听端口,即浏览器所访问的端口
uwsgi_pass 即uwsgi配置中的socket路径
2)启动nginx
直接输入命令nginx就行
5.在浏览器中访问
在浏览器中访问http://localhost:8080
在网页中显示hello world 则部署成功