Files
qing f9c02cd6ad feat(redirect80): new HTTP→HTTPS redirect service on port 80
Pure Python stdlib http.server + ThreadingMixIn, zero web framework deps.
- GET/HEAD → 301, POST/PUT/DELETE/PATCH → 308
- Reads Host header, strips port, redirects to https://{host}{path}
- Config via confs (retry_on_refused, hard dependency) + env var override
- Logs via log_client → db Logs table (fail-safe async batch)
- Port 80 privilege via setcap cap_net_bind_service in _run.sh
2026-08-02 12:50:23 +08:00

17 lines
626 B
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
cd "$(dirname "$0")" || exit
source venv/bin/activate
# 80 端口是特权端口(<1024),需要 CAP_NET_BIND_SERVICE 能力
# 尝试自动设置 cap(失败不阻塞,用户可手动 sudo 或用 systemd AmbientCapabilities)
_python_bin="$(readlink -f venv/bin/python3)"
if command -v setcap &>/dev/null; then
if sudo setcap 'cap_net_bind_service=+ep' "$_python_bin" 2>/dev/null; then
echo "[redirect80] 已为 $_python_bin 设置 cap_net_bind_service"
else
echo "[redirect80] ⚠ 无法设置 cap_net_bind_service,可能需要 root 运行"
fi
fi
exec python3 redirect80.py