部署到服务器笔记
1、生成二级域名,在阿里云的域名管理中,解析域名添加记录生成二级域名
2、添加ssl
确定等待审核
3、部署网站到“服务器”
① 压缩 项目文件夹 并 上传到 /var/wx , 解压
② 切换到项目文件下: pyenv local '环境' --> 设置python环境 注:pyenv versions 查看本机python环境list
③ 安装依赖
④ 然后 python manager.py runserver 看是否有错误 如果没有错误继续
⑤ 在 项目根目录下添加:项目名称_uwsgi.ini文件
[uwsgi]
# Django-related settings
socket = :8001 // 端口号
# the base directory (full path)
chdir = /var/wx/wxback // 项目路径
# Django s wsgi file
module = wxback.wsgi // wxback 项目名称
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 4
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
⑥ 运行 uwsgi --ini wxback_uwsgi.ini 通过uwsgi运行项目
⑦ 配置 nginx配置文件 添加:
server { listen 443 ssl; server_name wx.dayu1.net; ssl_certificate wx_cert/1533872371570.pem; ssl_certificate_key wx_cert/1533872371570.key; server_tokens off; fastcgi_param HTTPS on; fastcgi_param HTTP_SCHEME https; add_header Cache-Control no-cache; access_log /var/log/nginx/idimg_ssl.access.log; error_log /var/log/nginx/idimg_ssl.error.log; location / { root /var/www/html; index index.html index.htm; #include uwsgi_params; #uwsgi_pass 127.0.0.1:8000; #uwsgi_read_timeout 2; } location /api { include uwsgi_params; uwsgi_pass 127.0.0.1:8001; // 端口号配置正确 uwsgi_read_timeout 600; } }
之后重启nginx service nginx stop; service nginx start;
⑧ 修改 项目的 setting 文件中的:
ALLOWED_HOSTS = []
为:
ALLOWED_HOSTS = ['*']
⑨ 为了以后维护方便添加重启 uwsgi_restart.sh 脚本
NAME="wxback__uwsgi.init" // 文件名 if [ ! -n "$NAME" ];then echo "no arguments" exit; fi echo $NAME ID=`ps -ef | grep "$NAME" | grep -v "$0" | grep -v "grep" | awk '{print $2}'` echo $ID echo "################################################" for id in $ID do kill -9 $id echo "kill $id" done echo "################################################" uwsgi --ini /var/wx/wxback // 只到文件夹目录