jeessy2 / ddns-go

Simple and easy to use DDNS. Support Aliyun, Tencent Cloud, Dnspod, Cloudflare, Callback, Huawei Cloud, Baidu Cloud, Porkbun, GoDaddy, Namecheap, NameSilo...
MIT License
10.46k stars 1.2k forks source link

新增的 login 页面不支持二级目录的反代 #1137

Open yfdoor opened 1 month ago

yfdoor commented 1 month ago

问题描述

之前是可以通过 http://1235.com/ddns 这样来反代二级目录的,现在新增的 login 页面不会定位到 http://1235.com/ddns/login 下,而是 http://1235.com/login。导致页面显示出错

DNS服务商

No response

是否已搜索同类问题

已搜索,但未能解决

操作系统

Linux

架构

x86_64

版本

v6.6

安装方式

Docker

额外信息

No response

WaterLemons2k commented 1 month ago

见 #1129

yfdoor commented 1 month ago

见 #1129

按照上面的案例添加 rewrite

location ^~ /ddns/ {
    proxy_pass http://127.0.0.1:9876/; 
    proxy_set_header Host $host; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header REMOTE-HOST $remote_addr; 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection "upgrade"; 
    proxy_set_header X-Forwarded-Proto $scheme; 
    proxy_http_version 1.1; 
    add_header X-Cache $upstream_cache_status; 
    add_header Strict-Transport-Security "max-age=31536000"; 
    add_header Cache-Control no-cache; 
    rewrite /ddns/(.*) /$1 break;
}

还是跳转到 http://1235.com/login 页。。。

charley008 commented 3 days ago

+1, 6.6.3版,现在只能输入http://1235.com/ddns/login 才能正常使用。要不然还是出现上面的错误

charley008 commented 23 hours ago

通用chatgpt 找到一个凑合的办法:

location /ddns/ {
    proxy_pass http://127.0.0.1:9876/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
    add_header Cache-Control no-cache;
    add_header Strict-Transport-Security "max-age=31536000";
    rewrite /ddns/(.*) /$1 break;
    proxy_redirect / /ddns/;
}

这里添加了proxy_redirect / /ddns/;指令,这个指令会将后端返回的重定向响应头中的Location字段从/重写为/ddns/。这样,当后端应用重定向到/login时,Nginx会将其重写为/ddns/login。