1. 程式人生 > >Linux Django專案部署

Linux Django專案部署

步驟

1.資料庫的處理
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': '123', 'PORT': 3306, } MySQL使用者的定義 [email protected]'白名單' 白名單: 主機域IP地址 [email protected]'localhost' [email protected]'10.0.0.110' [email protected]
'10.0.0.%' [email protected]'10.0.0.0/255.255.240.0' [email protected]'10.0.0.5%' [email protected]'%' grant all grant select,update,insert root:資料庫DBA wd開發人員:grant select,insert,update,delete on day1130.* to [email protected]'10.0.0.%' identified by '1'; 解壓django專案,cd進到settings.py vim 編輯 ALLOWED_HOSTS
= ["*"]#改 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'bbs', 'HOST': "10.0.0.100", #改 'USER': 'bbs', #改 'PASSWORD': '123', #改 'PORT': 3306, } } 2. BBS專案部署 2.1 配置Nginx [[email protected] BBS]# vim /etc/nginx/conf.d/py.conf server { listen 80; 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:9090; uwsgi_param UWSGI_SCRIPT BBS.wsgi; uwsgi_param UWSGI_CHDIR /opt/BBS; } } 2.2 配置uwsgi 關閉所有已有的uwsgi程序 kill -9 `ps -ef |grep uwsgi|awk {'print $2'}` [[email protected] BBS]# vim uwsgi.ini [uwsgi] socket = 127.0.0.1:9090 master = true workers = 2 reload-mercy = 10 vacuum = true max-requests = 1000 limit-as = 512 buffer-size = 30000 #啟動uwsgi uwsgi --ini uwsgi.ini & 重啟nginx systemctl restart nginx ==================