步骤一:在阿里云上买服务器
步骤二:在本地写好django项目
步骤三:下载xftp,putty
步骤四:利用xftp将django拖入服务器中
步骤五:确保在服务器中下载好了,uwsgi,nginx,django
django:
pip3 install django2.0
nginx:
sudo apt-get update
sudo apt-get install nginx
uwsgi:
在你的本地电脑访问https://uwsgi-docs.readthedocs.io/en/latest/Download.html,下载Stable/LTS版本的源文件。
本地下解压这个源文件,然后用xftp把文件拖放到阿里云的Ubuntu的家目录(home)下,使用cd命令进入到该文件夹下,按顺序依次输入下面三条命令:
sudo apt-get install python3-setuptools
sudo apt-get install python3-dev
sudo python3 setup.py install
Mysql:
sudo apt-get install mysql-server mysql-client
mysql -u root -p
pymysql:
pip3 install pymysql
步骤六、修改文件-----使得django允许阿里云主机
项目中的settings文件
DEBUG = False
ALLOWED_HOSTS = ['*','47.101.128.123']
步骤七、修改文件-----让 nginx(网址默认服务器) 转向 uwsgi
进入etc/nginx/nginx.conf (配置文件)里,看里面有没有
server{
}
如果没有你可以看到在
http{
#里面有
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*; #这里把内容include进来的,去这两个地方看看
}
当然修改
/etc/nginx/sites-available 和 /etc/nginx/sites-enabled
是一样的,建议修改前者
server
{
server_name 192.168.1.121;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000; ######重要 这个端口一定不能被其他端口占了#####重要
}
location /static {
alias /home/feixue/python/www/for_test/static;
}
location /media {
alias /home/ubuntu/blog/media;
}
}
步骤八、修改文件-----配置uwsgi文件
在博客项目的根目录下,也就是有manage.py文件的目录下,新建一个uwsgi.ini文件和一个run.log文件
uwsgi.ini:
[uwsgi]
chdir = /home/1107-gdapi/gdapi
module = for_test.wsgi:application
socket = 127.0.0.1:8000 #########这个socket是和nginx连接的关键,所以需要保持一致再说一遍,端口不要被占!!
master = true
daemonize = /home/1107-gdapi/gdapi/run.log
disable-logging = true
步骤九、输入网址,成功