本專案提供完整的一鍵 Hardware System 佈署腳本,使用 Nginx + FastAPI + Uvicorn + Gunicorn 作為後端併發。
Pages: https://zz22558822.github.io/Hardware_System/
- Ubuntu 24.04 以上
- Python 3.8 以上
- Nginx
- SQLite
sudo權限
若環境僅用於此專案可使用非 venv版本,兩者擇一使用
sudo bash -c "$(wget -qO- https://raw.githubusercontent.com/zz22558822/Hardware_System/main/SQL/Hardware_System_install.sh)"sudo bash -c "$(wget -qO- https://raw.githubusercontent.com/zz22558822/Hardware_System/main/SQL/Hardware_System_install_venv.sh)"執行腳本後,請依照指示輸入:
- Domain (可輸入 IP 或網址)
- SSL 憑證有效天數 (預設 36499 天)
安裝完成後,切換至 FastAPI 目錄並啟動虛擬環境:
cd /home/$(whoami)/FastAPI
source /home/$(whoami)/VM/bin/activate
uvicorn main:app --reload或使用 Gunicorn 啟動:
gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app開啟 Web 即可使用:
https://your-domain安裝腳本會自動配置 Nginx,提供 HTTPS 支援。 若需修改 Nginx 設定,請編輯:
sudo nano /etc/nginx/sites-available/FastAPI修改完成後,重新載入 Nginx:
sudo systemctl restart nginx腳本會自動修改 main.py 內的 CORS 設定,確保 http://your-domain 和 https://your-domain 可正常存取 API。
- 確保防火牆允許 8000 和 443 端口:
sudo ufw allow 8000 sudo ufw allow 443
- 檢查 FastAPI 是否有正常執行:
ps aux | grep uvicorn
- 測試 Nginx 配置是否正確:
sudo nginx -t
- 重新啟動 Nginx:
sudo systemctl restart nginx
若需移除 Hardware System,可執行以下命令:
sudo systemctl stop nginx
sudo rm -rf /home/$(whoami)/FastAPI
sudo rm -rf /home/$(whoami)/VM
sudo rm -f /etc/nginx/sites-available/FastAPI
sudo rm -f /etc/nginx/sites-enabled/FastAPI
sudo systemctl restart nginx本專案基於 MIT License 發布,自由使用與修改。
