1.打開(kāi)pycharm寫(xiě)的項(xiàng)目,打開(kāi)命令工具,輸入
python manage.py check --deploy
如果你的準(zhǔn)備工作做好了就會(huì)沒(méi)有問(wèn)題,如果提示有很多警告,就參照官方文檔修改settings
2.進(jìn)入服務(wù)器,創(chuàng)建文件來(lái)放你的項(xiàng)目代碼
mkdir project
cd project
mkdir code
mkdir conf
mkdir stat
mkdir logs
cd code
git clone 你的項(xiàng)目地址(gitee或github三方托管平臺(tái))
cd ..
python3 -m venv venv
source venv/bin/activate
pip install -r code/fangtx/requirements.txt
cd conf
vim uwsgi.conf
[uwsgi]
# 配置前導(dǎo)路徑
base=/root/project
# 配置項(xiàng)目名稱
name=teamproject
# 守護(hù)進(jìn)程
master=true
# 進(jìn)程個(gè)數(shù)
processes=4
# 虛擬環(huán)境
pythonhome=%(base)/venv
# 項(xiàng)目地址
chdir=%(base)/code/%(name)
# 指定python解釋器
pythonpath=%(pythonhome)/bin/python
# 指定uwsgi文件
module=%(name).wsgi
# 通信的地址和端口(自己服務(wù)器的IP地址和端口)
socket=(ip地址):8000
# 日志文件地址
logto=%(base)/logs/uwsgi.log
python manage.py collectstatic
收集靜態(tài)資源到指定的STATIC_ROOT目錄
啟動(dòng)uWSGI服務(wù)器
uwsgi --ini conf/uwsgi.conf
pip install nginx
vim /etc/nginx/nginx.conf
刪除所有的server方法
加上
include /root/project/conf/nginx.conf;
vim /project/conf/nginx.conf
重寫(xiě)80端口server
server {
listen 80;
server_name _;
access_log /root/project/logs/access.log;
error_log /root/project/logs/error.log;
location / {
include uwsgi_params;
uwsgi_pass (私網(wǎng)IP地址);
}
location /static/ {
alias /root/project/stat/;
expires 30d;
}
}
下載證書(shū)到conf
重寫(xiě)443端口,類似80端口,參照官方文檔
重啟nginx
systemctl restart nginx