Django+Nginx个人博客环境搭建

  • 使用 Django + nginx
  • 组成 Django2 uwsgi python3.7 nginx

  • 环境搭建步骤
  1. 安装git

    • yum install git
  2. 安装python3.7

    • 教程 https://www.jianshu.com/p/7c2b62c37223
    • yum install gcc openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel libffi-devel tk-devel wget curl-devel
    • cd /tmp
    • wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
    • tar -zxvf Python-3.7.2.tgz
    • mkdir /usr/local/python3
    • Python-3.7.2/configure --prefix=/usr/local/python3/
    • 如果报错 configure: error: no acceptable C compiler found in $PATH
    • 安装 yum install gcc
    • 安装 yum -y install gcc automake autoconf libtool make
    • 安装 yum install gcc gcc-c++
    • make
    • make install
    • 添加软链接
    • ln -s /usr/local/python3/bin/python3 /usr/bin/python3
    • ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
  3. 安装Mysql

    • 教程 https://blog.csdn.net/qq_36582604/article/details/80526287
    • 安装
    • wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
    • yum -y install mysql57-community-release-el7-10.noarch.rpm
    • yum -y install mysql-community-server
        No match for argument: mysql-community-server
        Error: Unable to find a match: mysql-community-server
        
        解决:
        先执行:yum module disable mysql
        再执行:yum -y install mysql-community-server
    
    
    解决 systemd(systemctl) 相关命令的原因是 1号进程不是 init
    docker run -tid --name test --privileged=true ubuntu:18.04 /sbin/init
    docker exec -it test /bin/bash
    
    
    • 启动
    • systemctl start mysqld.service
    • 查看运行状态
    • systemctl status mysqld.service
    • 获取初始密码 dl#uPK4RCe5;
    • grep “password” /var/log/mysqld.log
    • 登录数据库(使用初始密码)
    • mysql -uroot -p
    • 修改成自己的密码
    • ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘你的密码!’;
    • 允许外网登录(不允许就把% 改成本地IP)
    • grant all privileges on . to ‘root’@’%’ identified by ‘你的密码!’ with grant option;
    • flush privileges;
    • exit
    • 防火墙
    • firewall-cmd --zone=public --add-port=3306/tcp --permanent
    • firewall-cmd --zone=public --add-port=8080/tcp --permanent
    • firewall-cmd --reload
    • 修改数据库编码
    • mysql -uroot -p
    • status
    • vi /etc/my.cnf
    • 新增四行代码
    • [client]
    • default-character-set=utf8
    • 这两行必须放到 socket后边
    • character-set-server=utf8
    • collation-server=utf8_general_ci
    • 重启mysql
    • service mysqld restart
    • 查看编码是否变为 utf-8
    • 尝试下远程连接,正常就完事
  4. 将项目上传到服务器

    • pip install pymysql
    • pip install django
    • 修改两处环境源码
      • 注释掉mysql版本限制
      • 146 行 decode 改成 encode
    • 到项目根目录下启动项目
    • python3 manage.py runserver
  5. 安装uwsgi

    • pip3 install uwsgi --upgrade

    • ln -s /usr/local/python3/lib/python3.7/bin /usr/bin/uwsgi

    • 如果软链接有问题,把软链接文件删掉后重新建立

    • find / -name uwsgi

    • 尝试启动服务

    • uwsgi --http :8888 --module eduonline.wsgi

    • 看到 spawned uWSGI worker 1 (and the only) (pid: 5715, cores: 1) 即为正常

    • 重启 uwsgi --reload /var/run/uwsgi.pid

    • 关闭 uwsgi --stop /var/run/uwsgi.pid

  6. 安装nginx

    • yum install epel-release
    • yum install python-devel nginx
  7. 启动服务器

    • 查看网络进程运行
    • uwsgi --ini /root/www/web/zjclassroom/uwsgi.ini
    • nginx -c /root/www/web/zjclassroom/webapp.conf
    • netstat -nltp (确保nginx 和 uwsgi 正常运行)
  8. 常见服务器操作命令

    • 重启nginx(css 有变动的时候,去掉缓存)
      • nginx -s reload
    • 关闭nginx
      • nginx -s stop
附录
  • 出现这个问题
    • The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting
    • STATIC_ROOT=os.path.join(BASE_DIR,“static”) 将这句,改成下面的样子就可以运行
    • STATIC_ROOT=os.path.join(BASE_DIR,"/static/")
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值