Django项目上线注意事项

上线注意事项:

  1. 修改settings.py文件
DEBUG = False
ALLOWED_HOSTS = ['*']


# 如果要用到pymysql,增加以下内容
import pymysql
# 告诉django用pymysql代替mysqldb连接数据库
pymysql.install_as_MySQLdb()

# 修改`DATABASES`中的配置
...
  1. 导出requirements.txt文件
~# pip3 freeze > requirements.txt
  1. 上传项目文件到服务器
  2. 服务器端配置
# 进入项目所在目录
~# cd /data/www/demo
# 安装依赖
~# pip3 install -r ./first/requirements.txt
# 安装uwsgi
~# yum install uwsgi
# 编缉配置文件
~# vim uwsgi.ini
[uwsgi]
master = true
processes = 1
threads = 2
# manage.py所在目录
chdir = /data/www/demo/first
# wsgi.py的绝对路径
wsgi-file= /data/www/demo/first/first/wsgi.py
# 监听的端口号
# 也可以是 http,可直接访问;socket需使用代理
# 如:http = 0.0.0.0:3032
socket = 0.0.0.0:3031
# 日志目录
logto = /data/www/demo/first/logs/error.log
chmod-socket = 660
vacuum = true
max-requests = 1000
  1. nginx配置
location /
{
    include uwsgi_params;
    uwsgi_pass  127.0.0.1:3031;
    uwsgi_param X-Real-IP $remote_addr;
    uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
    uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto;
}
  1. 启动项目
~# wsgi --ini uwsgi.ini -d /var/log/uwsgi.log

更新时间:2020-04-29 16:53:55

本文由 新逸Cary 创作,如果您觉得本文不错,请随意赞赏
采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
原文链接:https://blog.xinac.cn/archives/django-deploy.html
最后更新:2020-04-29 16:53:55

评论

Your browser is out of date!

Update your browser to view this website correctly. Update my browser now

×