ubuntu部署DJango项目全过程详细介绍附截图

Python私教 2018-12-16 13:00:49

修改源

清华的源

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main multiverse restricted universe

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main multiverse restricted universe

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main multiverse restricted universe

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main multiverse restricted universe

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main multiverse restricted universe

deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main multiverse restricted universe

deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main multiverse restricted universe

deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main multiverse restricted universe

deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main multiverse restricted universe

deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main multiverse restricted universe

配置nginx

server {

listen 80;

server_name localhost;

location / {

include uwsgi_params;

uwsgi_pass 127.0.0.1:8080;

}

location /static{

#指定静态文件存放的目录

alias /var/www/test/static/;

}

}

配置Django

配置uwsgi

[uwsgi]

#使用nginx连接时使用

socket = 127.0.0.1:8080

#直接做web服务器使用 python manage.py runserver ip:port

;http = 127.0.0.1:8080

#项目目录

chdir = /home/lxgzhw/python/django/hw_001_test

#项目中wsgi.py文件的目录,相对于项目目录

wsgi-file = hw_001_test/wsgi.py

#指定启动的工作进程数

processes = 4

#指定工作进程中的线程数

threads = 2

master = True

#保存启动之后主进程的pid

pidfile = uwsgi.pid

#设置uwsgi后台运行,uwsgi.log保存日志信息

daemonize = uwsgi.log

#设置虚拟环境的路径

;virtualenv = /Users/smart/.virtualenvs/dailyfresh

收集静态文件

python3 manage.py collectstatic

重启服务

sudo service nginx restart

uwsgi --ini uwsgi.ini

0 阅读:3

Python私教

简介:全栈工程师,目标人工智能.抖音同理想国真恵玩.