基于阿里云ESC服务器(ubuntu 18.04.5系统)利用Nginx + Gunicorn 部署的django项目流程

一、前言
之前在本地主机上写了一个django项目,最近又买了阿里云的学生服务器,就想着把这个django项目部署到服务器上。如今完成部署,发现自己踩过好多坑,就写了这篇文章来记录一下自己踩的坑,希望对你有帮助。第一次写文章,如有出错,请多多包涵与指正。

二、部署前的准备

  1. 有一台可以连接公网的服务器(我的系统是ubuntu 18.04.5)
  2. 可以运行的django项目
  3. 了解git与github(用于给服务器上传django项目)
  4. 了解一些基础的linux操作指令
  5. 一个可用的域名(如果没有也没关系,服务器公网ip也可以登录网站)
  6. 新手最好有一个可视化的SFTP工具(如WinSCP,可以方便操作)

三、开始部署
3.1搭建环境
如果你的服务器是“崭新出厂”的,请创建一个普通用户并赋予他超级权限。因为在root下部署代码不是很安全,且有可能出错。
创建一个拥有超级权限的用户步骤如下:

#创建新用户wss
root@VM-0-7-ubuntu:~# useradd -m -s /bin/bash wss
#新创建的用户加入超级权限组
root@VM-0-7-ubuntu:~# usermod -a -G sudo wss
#为新用户设置密码
root@VM-0-7-ubuntu:~# passwd wss
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
#切换到创建的新用户
root@VM-0-7-ubuntu:~# su - wss
#切换成功,@符号前面已经是新用户名而不是 root 了
wss@VM-0-7-ubuntu:~#

同时,记得更新一下系统,避免版本太老带来的一些困惑。(因为某些原因,我下面使用的还是root,没有用wss用户)

root@VM-0-7-ubuntu:~# sudo apt-get update
root@VM-0-7-ubuntu:~# sudo apt-get upgrade

安装一些必备的软件(挨个复制)

root@VM-0-7-ubuntu:~# sudo apt-get install nginx

root@VM-0-7-ubuntu:~# sudo apt-get install git python3 python3-pip

root@VM-0-7-ubuntu:~# sudo pip3 install virtualenv

#安装mysql
root@VM-0-7-ubuntu:~# sudo apt-get install mysql-server
root@VM-0-7-ubuntu:~# apt-get isntall mysql-client

#安装过程中会提示设置密码什么的,注意设置了不要忘了,安装完成之后可以使用如下命令来检查是否安装成功:
root@VM-0-7-ubuntu:~# sudo netstat -tap | grep mysql
(No info could be read for "-p": geteuid()=1000 but you should be root.)
tcp        0      0 localhost:mysql         *:*                     LISTEN      

#登陆mysql数据库可以通过如下命令
root@VM-0-7-ubuntu:~# mysql -u root -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.7.27-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
#查看当前的数据库
mysql> show databases;
+--------------------+
| Database           |
+---------------
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值