初始化 FastAPI HTTPS Hello World 服务

包含 FastAPI 应用、Nginx 反向代理配置、systemd 服务及腾讯云 pip 源配置。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Ubuntu
2026-06-04 21:59:53 +08:00
co-authored by Cursor
commit 5313206976
7 changed files with 51 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
venv/
__pycache__/
*.pyc
.env
+13
View File
@@ -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"}
+14
View File
@@ -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
+12
View File
@@ -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;
}
}
+3
View File
@@ -0,0 +1,3 @@
[global]
index-url = https://mirrors.cloud.tencent.com/pypi/simple/
trusted-host = mirrors.cloud.tencent.com
+2
View File
@@ -0,0 +1,2 @@
fastapi==0.115.12
uvicorn[standard]==0.34.2
Executable
+3
View File
@@ -0,0 +1,3 @@
#!/bin/bash
cd "$(dirname "$0")"
exec ./venv/bin/uvicorn app:app --host 127.0.0.1 --port 8000