Linux Django项目部署

时间:2023-03-10 05:41:37
Linux Django项目部署

步骤

.数据库的处理
1.1 上传bbs.sql
1.2 在mysql中创建bbs库,并导入数据库SQL脚本
mysql> create database bbs charset utf8mb4;
mysql> use bbs
mysql> source /opt/bbs.sql
mysql> drop database bbs; 1.3 查看项目settings.py配置文件,修改以下两处 ALLOWED_HOSTS = ['*'] DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'bbs',
'HOST': "10.0.0.100",
'USER': 'root',
'PASSWORD': '',
'PORT': ,
} MySQL用户的定义 USERNAME@'白名单' 白名单: 主机域IP地址 root@'localhost'
root@'10.0.0.110'
root@'10.0.0.%'
root@'10.0.0.0/255.255.240.0'
root@'10.0.0.5%'
root@'%' grant all
grant select,update,insert
root:数据库DBA
wd开发人员:grant select,insert,update,delete on day1130.* to wd@'10.0.0.%' identified by ''; 解压django项目,cd进到settings.py
vim 编辑
ALLOWED_HOSTS = ["*"]#改
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'bbs',
'HOST': "10.0.0.100", #改
'USER': 'bbs', #改
'PASSWORD': '', #改
'PORT': ,
}
} . BBS项目部署 2.1 配置Nginx
[root@web01 BBS]# vim /etc/nginx/conf.d/py.conf
server {
listen ;
server_name 10.0.0.100;
client_max_body_size 100M; location /static {
alias /opt/BBS/static/;
} location /media {
alias /opt/BBS/media;
} location / {
index index.html;
include uwsgi_params;
uwsgi_pass 127.0.0.1:;
uwsgi_param UWSGI_SCRIPT BBS.wsgi;
uwsgi_param UWSGI_CHDIR /opt/BBS;
}
} 2.2 配置uwsgi
关闭所有已有的uwsgi进程
kill - `ps -ef |grep uwsgi|awk {'print $2'}` [root@web01 BBS]# vim uwsgi.ini
[uwsgi]
socket = 127.0.0.1:
master = true
workers =
reload-mercy =
vacuum = true
max-requests =
limit-as =
buffer-size = #启动uwsgi
uwsgi --ini uwsgi.ini & 重启nginx
systemctl restart nginx ==================