创建目录
mkdir mygpt
cd mygpt
创建虚拟环境
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python3.8-venv
python3 -m venv djangoENV
source djangoENV/bin/activate #激活
source venv/bin/activate
安装必要模块
pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
pip freeze > requirements.txt #生成
openai==0.27.4
python-dotenv==0.21.1
djangorestframework==3.14.0
PyMySQL==1.0.2
Django==4.1.7
django-cors-headers==3.14.0
uwsgi
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install uwsgi -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install uwsgi -i https://pypi.tuna.tsinghua.edu.cn/simple --use-pep517
pip install mysqlclient -i https://pypi.tuna.tsinghua.edu.cn/simple
(
sudo apt-get install python-dev #不装这个装不上uwsgi
sudo apt-get install python3-dev
sudo apt-get install build-essential
sudo apt-get install python3-dev default-libmysqlclient-dev build-essential
)
gitee仓库
git init
git remote add origin https://gitee.com/jianxinboke/wegptapi.git
#git pull origin master
git add .
git commit -m 'GPT项目第一次到gitee'
git push origin master
git clone ~~~~
编写uwsgi.ini文件
[uwsgi]
socket =127.0.0.1:8000
chdir = /home/wjx/mygpt/gptAPI
module = gptAPI.wsgi
master = true
processes = 4
vacuum = true
py-autoreload = 1
启动项目
uwsgi --ini uwsgi.ini
uwsgi --reload uwsgi.ini #重启
uwsgi --stop uwsgi.ini
pkill -f uwsgi -9 #杀死进程
Nginx
#安装
sudo apt install nginx
#配置
cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak
sudo vim /etc/nginx/sites-available/default
server {
listen 9090;
server_name 8.130.98.187;
charset UTF-8;
access_log /var/log/nginx/myweb_access.log;
error_log /var/log/nginx/myweb_error.log;
client_max_body_size 75M;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
uwsgi_read_timeout 2;
}
}
django目录下启动uwsgi
uwsgi --ini uwsgi.ini
uwsgi --reload uwsgi.ini #重启
uwsgi --stop uwsgi.ini
启动Nginx
systemctl restart nginx
#或者
sudo /etc/init.d/nginx restart
#查看情况
ps -ef|grep nginx
将 uWSGI 配置为开机自启
sudo vi /etc/rc.local
uwsgi --ini /home/wjx/mygpt/gptAPI/uwsgi.ini &
在启动 uwsgi 进程时,使用 nohup 命令将其置于后台运行,例如:
nohup uwsgi --ini your_config.ini &
nohup uwsgi --ini uwsgi.ini &