簡單的安裝過程可以在這里找到,這里主要說一下如何配置uwsgi的服務,將uwsgi服務加入系統進程,你可以使用如下兩種方式安裝
apt-get
apt-get install uwsgi
該命令會自動將uwsgi安裝為一個服務,在 /etc/init.d/uwsgi 下,你可以使用以下命令來管理該服務:
sudo /etc/init.d/uwsgi start|stop|restart|reload sudo service uwsgi start|stop|restart|reload
pip
pip install uwsgi
該命令會將uwsgi安裝在 /usr/local/bin/uwsgi ,你需要手動添加服務,建立 /etc/ini/uwsgi.conf 文件,內容如下:
description "uWSGI Emperor" start on runlevel [2345] stop on runlevel [!2345] respawn exec /usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals/ --logto /var/log/uwsgi/uwsgi.log
然后你就可以通過如下的命令來管理uwsgi的進程了:
sudo initctl start|stop|restart|reload| uwsgi sudo service uwsgi start|stop|restart|reload
為你的網站創建配置文件
在 /etc/uwsgi/vassals/ 目錄下創建一個ini的配置文件,內容如下:
[uwsgi] virtualenv=/home/cungen/sdk/python/env/ chdir=/var/www/api.cungen.tk chmod-socket=777 chown-socket=www-data module=www.wsgi env=DJANGO_SETTINGS_MODULE=www.settings master=True vacuum=True socket=/tmp/api.cungen.tk.sock pidfile=/tmp/api.cungen.tk.pid daemonize=/var/log/uwsgi/api.cungen.tk.log gid=www-data uid=www-data
virtualenv為你使用的virtualenv的路徑,chdir為你的項目路徑,module為你項目中的模塊,%n改為你的項目名稱即可
修改nginx中項目的配置文件
如我的為 /etc/nginx/sites-available/api.local.cg ,內容如下:
server { listen 80; root /var/www/api.cungen.tk; index index.html index.htm; access_log /var/log/nginx/api.cungen.tk-access; error_log /var/log/nginx/api.cungen.tk-error error; server_name api.cungen.tk; location / { try_files $uri @django; } location @django { uwsgi_pass unix:///tmp/api.cungen.tk.sock; include uwsgi_params; } ## caches include /etc/nginx/conf.d/caches.conf; }
重啟服務:
sudo service nginx reload sudo service uwsgi reload
摘自:http://stackoverflow.com/questions/23073829/uwsgi-wont-reload-restart-or-let-me-run-service