1, 安装uWSGI server
sudo apt-get install uwsgi uwsgi-plugin-python2, 在 /etc/uwsgi/apps-available 目录下创建配置文件
appsample.json
内容如下
{ "uwsgi": { "chdir": "/home/yourdir", "uid": "your-userid", "gid": "www-data", "workers": 8, "module": "appsample:mkapplication()", "pythonpath": "/path/to/the/directory/where/yourapp.py/is/found", "show-config": true, "stats": "127.0.0.1:9191" } }
3, 创建一个link
sudo ln -s /etc/uwsgi/apps-available/appsample.json /etc/uwsgi/apps-enabled/appsample.json</pre>4,restart uwsgisudo service uwsgi restart
5,通过如下就可以访问uwsgi --connect-and-read 127.0.0.1:9191
6,为了便于检测stat server,可以安装sudo pip install uwsgitop然后通过uwsgitop检测uwsgi的运行uwsgitop 127.0.0.1:91917, 为了在apache2里面使用uwsgi的话,需要安装libapache2-mod-uwsgi
sudo apt-get install libapache2-mod-uwsgi
然后在apache2里面添加如下配置最后reload apache2配置即可<Location /myapi> SetHandler uwsgi-handler uWSGISocket /run/uwsgi/app/appsample/socket </Location>这样通过访问 http://localhost/myapi/apache2就会把访问请求重定向到uwsgi的应用程序8, 为了在python程序中通过写log,比如os.makedirs(os.path.join('logs', client-ip-or-domain))
需要将
/home/yourdir
里面的logs文件夹改写为 www-data的权限