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:9191
7, 爲了在apache2裏面使用uwsgi的話,需要安裝libapache2-mod-uwsgi
sudo apt-get install libapache2-mod-uwsgi
然後在apache2裏面添加如下配置
<Location /myapi>
SetHandler uwsgi-handler
uWSGISocket /run/uwsgi/app/appsample/socket
</Location>
最後reload apache2配置即可這樣通過訪問 http://localhost/myapi/
apache2就會把訪問請求重定向到uwsgi的應用程序
8, 爲了在python程序中通過寫log,比如
os.makedirs(os.path.join('logs', client-ip-or-domain))
需要將
/home/yourdir
裏面的logs文件夾改寫爲 www-data的權限