故事背景
通过 cloudflare tunnel 访问vps服务器上的 sillytavern
使用 nginx 端口转发, 限制为仅允许 tunnel 发起的本地访问, 并修改请求header除去
安装 nginx
sudo apt-get install nginx
检查服务状态
systemctl status nginx
修改配置
修改 /etc/nginx/nginx.conf
文件 需要 sudo 以 root 权限编辑
http {
在这里添加添加
}
在 http 层级中添加
server {
# server name and port used by accessor (visit http://127.0.0.1:7000)
listen 7000;
server_name 127.0.0.1;
# for url path '/' and sub
location / {
# allow only local access the allow and deny line order matters
allow 127.0.0.1;
deny all;
# clear forwarded ip in header to pass upstream http service`s whitelist
proxy_set_header X-Real-Ip "";
proxy_set_header X-Forwarded-For "";
# the upstream http service
proxy_pass http://127.0.0.1:8000;
}
}
检查修改是否合法
sudo /usr/sbin/nginx -t
应用配置
sudo nginx -s reload
验证转发生效情况, 通过这两个端口应该都可以看到服务返回的内容
curl 127.0.0.1:7000
curl 127.0.0.1:8000
此时 从外部访问 nginx 代理端口 7000 是无法访问的
使用默认 8000 端口的 SillyTavern 默认同样不允许外部访问
同时 还可以在服务器主机上配置防火墙阻止所有到 7000/8000 端口的 TCP UDP 访问
以 claw cloud 为例
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。