Nginx 反向代理与 HTTPS 配置实践

安装 Nginx sudo apt update sudo apt install nginx sudo systemctl enable --now nginx 反向代理配置示例 以代理本地 vLLM 服务(监听 127.0.0.1:8000)为例: # /etc/nginx/sites-available/api.example.com server { listen 80; server_name api.example.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; # 流式响应(SSE)需要关闭缓冲 proxy_buffering off; proxy_read_timeout 300s; } } sudo ln -s /etc/nginx/sites-available/api.example.com /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl reload nginx 使用 Let’s Encrypt 签发 HTTPS 证书 sudo apt install certbot python3-certbot-nginx sudo certbot --nginx -d api.example.com certbot 会自动修改配置文件,添加 443 端口监听与证书路径,并配置 HTTP 到 HTTPS 的重定向。证书默认 90 天有效期,certbot 会自动注册续期任务,可通过以下命令验证: ...

2026-07-27 · 1 min · 147 words · ITNote

使用 Docker 容器化部署 AI 推理服务

为什么容器化 AI 服务 环境隔离,避免 CUDA / Python 依赖版本冲突 便于在多台机器间快速复制部署 结合编排工具(Compose / K8s)实现弹性伸缩 前提:安装 NVIDIA Container Toolkit distribution=$(. /etc/os-release; echo $ID$VERSION_ID) curl -s -L https://nvidia.github.io/libnvidia-container/gpgkey | sudo apt-key add - curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list \ | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list sudo apt update sudo apt install -y nvidia-container-toolkit sudo nvidia-ctk runtime configure --runtime=docker sudo systemctl restart docker 使用官方 vLLM 镜像启动服务 docker run -d \ --name vllm-server \ --gpus all \ -p 8000:8000 \ --ipc=host \ -v ~/.cache/huggingface:/root/.cache/huggingface \ vllm/vllm-openai:latest \ --model Qwen/Qwen2.5-7B-Instruct-AWQ \ --quantization awq 要点说明: ...

2026-07-27 · 1 min · 157 words · ITNote

systemd 服务管理与开机自启配置详解

编写一个基础 unit 文件 # /etc/systemd/system/myapp.service [Unit] Description=My Application After=network.target [Service] Type=simple User=appuser Group=appuser WorkingDirectory=/opt/myapp ExecStart=/opt/myapp/venv/bin/python app.py Restart=on-failure RestartSec=5 Environment=PYTHONUNBUFFERED=1 EnvironmentFile=-/opt/myapp/.env [Install] WantedBy=multi-user.target 关键字段说明: Type=simple:主进程即服务本身,适合大多数常驻程序 Restart=on-failure:进程异常退出时自动重启,避免服务假死 EnvironmentFile=-:前缀 - 表示文件不存在也不报错 常用管理命令 sudo systemctl daemon-reload # 修改 unit 文件后重新加载 sudo systemctl start myapp sudo systemctl enable myapp # 设置开机自启 sudo systemctl status myapp sudo systemctl restart myapp sudo systemctl stop myapp sudo systemctl disable myapp 查看日志 journalctl -u myapp -f # 实时跟踪日志 journalctl -u myapp --since today journalctl -u myapp -p err # 只看错误级别日志 资源限制 对 AI 推理等资源密集型服务,建议在 unit 中限制资源占用,避免单个服务拖垮整机: ...

2026-07-27 · 1 min · 118 words · ITNote