如何正确的使用uwsgi

简单的安装过程能够在这里找到,这里主要说一下如何配置uwsgi的服务,将uwsgi服务加入系统进程,你能够使用以下两种方式安装html

apt-get

apt-get install uwsgi

该命令会自动将uwsgi安装为一个服务,在 /etc/init.d/uwsgi 下,你能够使用如下命令来管理该服务:python

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 文件,内容以下:nginx

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的进程了:django

sudo initctl start|stop|restart|reload| uwsgi
sudo service uwsgi start|stop|restart|reload

为你的网站建立配置文件

在 /etc/uwsgi/vassals/ 目录下建立一个ini的配置文件,内容以下:api

[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改成你的项目名称便可socket

修改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;
}

 重启服务:ui

sudo service nginx reload
sudo service uwsgi reload

 

摘自:http://stackoverflow.com/questions/23073829/uwsgi-wont-reload-restart-or-let-me-run-servicespa

相关文章
相关标签/搜索