@nemos
2017-05-06T02:49:44.000000Z
字数 2049
阅读 833
web
the web client <-> the web server(nginx) <-> the socket <-> uwsgi <-> Django
sudo apt-get install nginx
apt-get install python-dev #不安装这个,下面的安装可能会失败
pip install uwsgi
sudo /etc/init.d/nginx start
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx restart
sudo service nginx start
sudo service nginx stop
sudo service nginx restart
将uwsgi_params
拷到项目目录下
cp /etc/nginx/uwsgi_params /path/to
在项目目录下创建 xxx_uwsgi.ini
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /path/to/your/project
# Django's wsgi file
module = project.wsgi
# the virtualenv (full path)
# home = /path/to/virtualenv
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /path/to/your/project/mysite.sock
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
从配置文件中运行
uwsgi --ini xxx_uwsgi.ini
在项目目录下创建xxx_nginx.conf
# 连接到django配置
upstream django {
# server unix://xxx.sock; #使用sock协议,并指定sock文件
# server 127.0.0.1:8001; #使用tcp协议,指定端口
}
# 服务器的配置
server {
listen 80;
server_name .example.com;
charset utf-8;
client_max_body_size 75M; # max upload size
location /media {
alias /path/to/your/mysite/media;
}
location /static {
alias /path/to/your/mysite/static;
}
# 非/media和/staic请求转接到django
location / {
uwsgi_pass django;
include /path/to/your/mysite/uwsgi_params; # the uwsgi_params file you installed
}
}
激活,连接配置文件
ln -s /path/to/nginx.conf /etc/nginx/sites-enabled/
在setting中添加
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
生成静态文件
python manage.py collectstatic
/etc/rc.local
添加到exit 0
之前
/usr/local/bin/uwsgi --socket /path/to/mysite.sock --module /path/to/mysite.wsgi --chmod-socket=666
安装 supervisor
(sudo) pip install supervisor
生成配置文件
(sudo) echo_supervisord_conf > /etc/supervisord.conf
添加
[program:project]
command=/path/to/uwsgi --ini /path/to/uwsgi.ini
directory=/path/to/project
startsecs=0
stopwaitsecs=0
autostart=true
autorestart=true
启动supervisor
(sudo) supervisord -c /etc/supervisord.conf
重启项目
(sudo) supervisorctl -c /etc/supervisord.conf restart project
其他命令
(sudo) supervisorctl -c /etc/supervisord.conf [start|stop|restart] [program-name|all]