本文以 DCRMv4 环境配置为例,系统为 Centos 7.3
基础依赖
yum install git nginx mysql-server mysql-devel python-devel
注意:mysql-devel python-devel
在 Ubuntu 下为 libmysqlclient-dev python-dev
缺少上述两个依赖会导致
如果已经编译安装过 MySQL 和 Nginx 则无需使用 yum 安装
Django 环境安装
pip install appdirs==1.4.3 chardet==2.3.0 click==6.7 Django==1.10.5 MySQL-python==1.2.5 olefile==0.44 packaging==16.8 pyparsing==2.2.0 python-debian==0.1.28 pytz==2017.2 six==1.10.0 sqlparse==0.2.3 uWSGI==2.0.14
USWGI 配置文件启动
配置文件 dcrm.ini
[uwsgi]
chdir = /wwwdata/DCRM
module = DCRM.wsgi
master = true
processes = 4
socket = :8001
vaccum = true
uid = 1001
gid = 1001
启动命令
uwsgi --ini dcrm.ini --daemonize=/dev/null # 修改 dcrm.ini 为实际的配置文件路径
每次修改代码后都需要重启 UWSGI
USWGI 重启脚本
NAME="dcrm" #修改为 module 的值
if [ ! -n "$NAME" ];then
echo "no arguments"
exit;
fi
ID=`ps -ef | grep "$NAME" | grep -v "$0" | grep -v "grep" | awk '{print $2}'`
echo "Stoping UWSGI"
for id in $ID
do
kill -9 $id
echo "kill $id"
done
echo "Starting UWSGI..."
uwsgi --ini dcrm.ini --daemonize=/dev/null # 修改 dcrm.ini 为实际的配置文件名称
Nginx 配置
upstream django {
server 127.0.0.1:8001;
}
server
{
listen 80;
#listen [::]:80;
server_name beta.uozi.org;
rewrite ^(.*)$ https://$host$1 permanent;
access_log /home/wwwlogs/beta.uozi.org.log;
}
server
{
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name beta.uozi.org ;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/beta.uozi.org;
ssl on;
ssl_certificate /etc/letsencrypt/live/beta.uozi.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/beta.uozi.org/privkey.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_session_cache builtin:1000 shared:SSL:10m;
# openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;
#error_page 404 /404.html;
error_page 497 https://$host$uri?$args;
server_name_in_redirect off;
location = / {
rewrite ^ /index/ last;
}
location / {
try_files $uri $uri/ @djangosite;
}
location ~^/static/(.*)$ {
alias /home/wwwroot/beta.uozi.org/WEIPDCRM/static/$1;
}
location ~^/resources/(.*)$ {
alias /home/wwwroot/beta.uozi.org/resources/$1;
}
location ~^/((CydiaIcon.png)|(Release(.gpg)?)|(Packages(.gz|.bz2)?))$ {
alias /home/wwwroot/beta.uozi.org/resources/releases/1/$1;
}
location @djangosite {
uwsgi_pass django;
include /usr/local/nginx/conf/uwsgi_params;
}
location ~* .(ico|gif|bmp|jpg|jpeg|png|swf|js|css|mp3|m4a|m4v|mp4|ogg|aac)$ {
expires 30d;
valid_referers none blocked *.82flex.com 127.0.0.1 localhost;
if ($invalid_referer) {
return 403;
}
}
access_log /home/wwwlogs/beta.uozi.org.log;
}
配置文成后还需要执行
./manage.py collectstatic
./manage.py migrate
./manage.py createsuperuser
来收集静态文件、同步数据库结构、创建网站管理员
Memcached、Redis 的配置方法:https://github.com/82Flex/DCRM
评论 (0)