收集Django静态文件
python manage.py collectstatic
升级Python并安装虚拟环境
略
安装配置Nginx
- 安装
wget http://nginx.org/packages/centos/6/x86_64/RPMS/nginx-1.12.0-1.el6.ngx.x86_64.rpm
rpm -ivh nginx-1.12.0-1.el6.ngx.x86_64.rpm
- 配置
vi /etc/nginx/conf.d/projects.conf
配置如下:
server {
listen 80;
server_name projects.test.com;
access_log /var/log/nginx/projects.access.log main;
error_log /var/log/nginx/projects.error.log warn;
client_max_body_size 10m;
location / {
root /home/lee/projects;
index index.html index.htm;
include uwsgi_params;
uwsgi_pass 127.0.0.1:8001;
expires -1;
}
location /static/ {
alias /home/lee/projects/static/;
expires -1;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
- 重启ngin服务并设置开机启动
service nginx restart
chkconfig nginx on
安装配置uwsgi
- 安装
pip install uwsgi
- 配置
在Django项目目录下新建uwsgi.ini文件,配置如下:
[uwsgi]
chdir = %d
socket = %d/../var/run/projects_uwsgi.sock
chmod=777
wsgi-file = %d/projects/wsgi.py
processes = 4
threads = 8
stats = 127.0.0.1:9000
vacuum = true
logto = %d/../var/log/projects_uwsgi.log
pidfile = %d/../var/run/projects_uwsgi.pid
master = true
disable-logging = true
buffer-size = 32768
virtualenv = /home/lee/.virtualenvs/projects
harakiri = 60
安装配置supervisor
- 安装
pip install supervisor
- 配置
echo_supervisord_conf > /etc/supervisord.conf
vi /etc/supervisord.conf
末尾加入
[program:uwsgi]
user=lee
drectory = /home/lee/projects
command = /usr/local/bin/uwsgi --ini /home/lee/projects/uwsgi.ini
autostart=true
autorestart=true
environment=DJANGO_SETTINGS_MODULE="projects.settings_product"
- 启动supervisor
/usr/local/bin/supervisord -c /etc/supervisord.conf
- 设置supervisor开机启动
将"/usr/local/bin/supervisord -c /etc/supervisord.conf“”写到/etc/rc.local