数据库课设完成了
创建非 root 用户
如果是使用 root 用户,应用代码有漏洞将威胁整个 vps ,非 root 用户只能修改被授权的文件,影响的是项目的文件夹。
sudo apt update && sudo apt upgrade -y
sudo adduser web
sudo usermod -aG sudo web
su - web
安装 python 环境
sudo apt install -y python3-venv python3-pip git ufw
上传项目授权
可以使用 git 上传,如果是用私库要生成公钥上传到账号里面。我这里是使用 sftp 上传,由于 sftp 对传输的文件都要握手,所以压缩之后上传。
sudo mkdir -p /var/www/library_system
sudo chown -R web:web /var/www/library_system # 将web目录权限交给web用户
开启 ufw
ufw allow OpenSSH
ufw allow 80
ufw allow 443
ufw enable
ufw status
安装依赖
python3 -m venv venv # 创建虚拟环境
source venv/bin/activate
pip install -r requirements.txt
启动Gunicorn
gunicorn --workers 3 --bind 127.0.0.1:8000 app:app
写入以下内容
sudo nano /etc/systemd/system/your_project.service
[Unit]
Description=Gunicorn instance to serve the Library System Flask app
After=network.target
[Service]
User=web
Group=web
WorkingDirectory=/var/www/library_system
ExecStart=/var/www/library_system/.venv/bin/gunicorn -w 4 --bind 127.0.0.1:8000 app:app
Restart=always
PrivateTmp=true
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload # 重新加载
sudo systemctl start library_system.service # 启动项目
sudo systemctl status library_system.service # 查看状态active说明正常运行
安装 caddy 反向代理
准备工作 :安装一些必要的工具
Sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
添加 Caddy 的 GPG 密钥
curl -1 sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring. Gpg
添加 Caddy 的 apt 仓库
curl -1 sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources. List. D/caddy-stable. List
更新包列表并安装 Caddy
Sudo apt update
Sudo apt install caddy
编辑 caddyfile 文件
sudo nano /etc/caddy/Caddyfile
yourdomain.com {
# 将所有请求反向代理到你本地运行的 Gunicorn 服务
reverse_proxy 127.0.0.1:8000
}
重启加载 caddyfile 的配置
sudo systemctl reload caddy
遇到的问题
由于是 windows 开发的,requirements. txt 文件没有写入 gunicorn。
Ai 幻觉依旧,只能借助不能依靠。
验收完成,堂堂结束
课设过程一直被摆子队友吸血,突然想到《天道》里面的话
强势文化就是遵循事物规律的文化,弱势文化就是依赖强者的道德期望破格获取的文化,也是期望救世主的文化。
我的理解是最好不要对其他人抱有能解决自己困难的期望,从来没有什么救世主。有什么想法只能自己去实现。


评论区(暂无评论)