commit 531320697678b90e791e14e508e8189b15f4a05c Author: Ubuntu Date: Thu Jun 4 21:59:53 2026 +0800 初始化 FastAPI HTTPS Hello World 服务 包含 FastAPI 应用、Nginx 反向代理配置、systemd 服务及腾讯云 pip 源配置。 Co-authored-by: Cursor diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2b91c72 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +venv/ +__pycache__/ +*.pyc +.env diff --git a/app.py b/app.py new file mode 100644 index 0000000..6102c83 --- /dev/null +++ b/app.py @@ -0,0 +1,13 @@ +from fastapi import FastAPI + +app = FastAPI(title="hair") + + +@app.get("/") +async def hello(): + return {"message": "Hello, World!"} + + +@app.get("/health") +async def health(): + return {"status": "ok"} diff --git a/hair.service b/hair.service new file mode 100644 index 0000000..28a328c --- /dev/null +++ b/hair.service @@ -0,0 +1,14 @@ +[Unit] +Description=Hair FastAPI Application +After=network.target + +[Service] +Type=simple +User=ubuntu +WorkingDirectory=/home/ubuntu/hair +ExecStart=/home/ubuntu/hair/venv/bin/uvicorn app:app --host 127.0.0.1 --port 8000 +Restart=always +RestartSec=3 + +[Install] +WantedBy=multi-user.target diff --git a/nginx/hair.conf b/nginx/hair.conf new file mode 100644 index 0000000..0b8250f --- /dev/null +++ b/nginx/hair.conf @@ -0,0 +1,12 @@ +server { + listen 80; + server_name hair.xiangsilian.com; + + location / { + proxy_pass http://127.0.0.1:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} diff --git a/pip.conf b/pip.conf new file mode 100644 index 0000000..6f2a15f --- /dev/null +++ b/pip.conf @@ -0,0 +1,3 @@ +[global] +index-url = https://mirrors.cloud.tencent.com/pypi/simple/ +trusted-host = mirrors.cloud.tencent.com diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..336a1d9 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +fastapi==0.115.12 +uvicorn[standard]==0.34.2 diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..77c7e57 --- /dev/null +++ b/start.sh @@ -0,0 +1,3 @@ +#!/bin/bash +cd "$(dirname "$0")" +exec ./venv/bin/uvicorn app:app --host 127.0.0.1 --port 8000