故事背景
通過 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 為例