进入服务器链接 ssh ubuntu@id
sudo apt update 和 sudo apt upgrade
安装pip:sudo apt install python3-pip
安装虚拟环境 sudo pip3 install virtualenv
报错解决方法
echo "export LC_ALL=en_US.UTF-8"
echo "export LC_ALL=en_US.UTF-8"
退出 exit 从新进解决方法:sudo pip3 install virtualenvwrapper
配置虚拟环境 vi .bashrc 复制这三条命令到文档
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
激活 source .bashrc创建虚拟环境
安装数据库 sudo apt-get install mysql-server mysql-client
导出本地数据库 mysqldump -uroot -p 1807_blog_db > /Users/xiaoyuan/Desktop/blog.sql
导出本地依赖第三方 pip freeze > requirements.txt
上传到服务器 git scp
在云端创建一个和本地数据库一样的库,并导入数据 source /xxx/xx/xx/blog.sql
安装nginx sudo apt-get install nginx
安装uwsgi pip install uwsgi-
uwsgi配置:
[uwsgi]Django-related settings
http = 127.0.0.1:8000
socket = 127.0.0.1:8000
chdir = /Users/xiaoyuan/Desktop/1807projects/MyBlog
module = MyBlog.wsgi
master = true
processes = 4
threads = 2
daemonize = uwsgi.log
pidfile = uwsgi.pid
virtualenv = /Users/xiaoyuan/.virtualenvs/1807_blog
收集静态资源:
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
python3 manage.py collectstatic
nginx配置 sudo apt install nginx /etc/nginx
写到http括号下
server {
listen 80;
server_name localhost;
#动态请求
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8001;
}
#静态
location /static {
alias /Users/xiaoyuan/Desktop/py_projects/MyBlog/static ;
}
}
启动nginx
/etc/init.d/nginx start 启动
/etc/init.d/nginx stop 或killall -9 nginx 关闭
/etc/init.d/nginx restart 重启 启动uwsgi
uwsgi --ini uwsgi.ini 启动
uwsgi --stop uwsgi.pip 关闭启动nginx
/etc/init.d/nginx start 启动
/etc/init.d/nginx stop 或killall -9 nginx 关闭
/etc/init.d/nginx restart 重启完成