第 1 步:DNS 解析
您需要先将您的域名 www.xxx.com 指向您的新加坡服务器。
相关服务:新加坡大带宽服务器租用
第 2 步:在新加坡服务器上配置反向代理
方案一:使用 Caddy (强烈推荐,极其简单)
- 在新加坡服务器上安装 Caddy
如果您的服务器是 Ubuntu/Debian,可以使用以下命令安装:
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
- 配置 Caddyfile
Caddy 的主配置文件是 /etc/caddy/Caddyfile。用编辑器(如 nano 或 vim)打开它:
sudo nano /etc/caddy/Caddyfile
将里面的内容全部删除,然后粘贴以下配置:
www.xxx.com {
# 将所有请求反向代理到 Google API
reverse_proxy https://generativelanguage.googleapis.com {
# 关键:将 Host Header 修改为目标服务器的 Host
# 否则 Google 服务器会收到 Host: www.xxx.com的请求而拒绝服务
header_up Host {upstream_hostport}
}
# 可选:增加一些日志记录,方便排错
log {
output file /var/log/caddy/geminiapi.log
}
}
- 启动 Caddy
保存并关闭文件后,重启 Caddy 使配置生效。
sudo systemctl restart caddy
Caddy 会自动为 www.xxx.com 申请并配置 Let’s Encrypt 的免费 SSL 证书。您无需任何手动操作!
