前言
此项目说明文档很详细,附有教程。适合初学者学习django开发。
部署
下载项目
git clone https://github.com/confucianzuoyuan/bookstore.git
安装python虚拟环境
# 安装
yum install python3 python3-devel python3-pip
# 激活
pip3 install virtualenv
virtualenv -p python3 py3 https://pypi.tuna.tsinghua.edu.cn/simple/
source py3/bin/activate
# 安装模块
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
创建数据库
CREATE DATABASE `bookstore` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
create user 'bkuser'@'%' IDENTIFIED BY 'bkxxx123';
grant all privileges on bookstore.* to 'bkuser'@'%';
flush privileges;.
开发模式启动
# 更新数据视图
python manage.py makemigrations
python manage.py migrate
# 启动
python manage.py runserver 172.16.4.10:8011
nginx 配置
server {
listen 80;
server_name www.bookstore.com; #换成自己的域名
location / {
proxy_pass http://172.16.4.10:8011;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
访问
首页
http://www.bookstore.com/
后台
# 添加超级管理员
python manage.py createsuperuser
http://www.bookstore.com/admin/
FAQ
nginx启动报错
# 修改systemd配置延迟启动
mkdir -p /etc/systemd/system/nginx.service.d
# 配置内容
vim /etc/systemd/system/nginx.service.d/override.conf
[Service]
ExecStartPost=/bin/sleep 0.1
# 重启服务
systemctl daemon-reload
systemctl restart nginx
评论 (0)