fix!: reverse proxy to sub-directory (#3483)

from this commit, if you want reverse proxy to sub-directory like `alist` with `nginx`, you need config:

```nginx
location /alist/ {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Range $http_range;
    proxy_set_header If-Range $http_if_range;
    proxy_redirect off;
    proxy_pass http://127.0.0.1:5244/alist/;
    # the max size of file to upload
    client_max_body_size 20000m;
}
```
This commit is contained in:
Andy Hsu
2023-02-18 19:03:07 +08:00
parent 3c7512f64a
commit 6c2f3486fc
7 changed files with 51 additions and 52 deletions

View File

@ -1,7 +1,6 @@
package static
import (
"net/url"
"strings"
"github.com/alist-org/alist/v3/internal/conf"
@ -15,20 +14,16 @@ type SiteConfig struct {
}
func getSiteConfig() SiteConfig {
u, err := url.Parse(conf.Conf.SiteURL)
if err != nil {
utils.Log.Fatalf("can't parse site_url: %+v", err)
}
siteConfig := SiteConfig{
ApiURL: conf.Conf.SiteURL,
BasePath: u.Path,
BasePath: conf.URL.Path,
Cdn: strings.ReplaceAll(strings.TrimSuffix(conf.Conf.Cdn, "/"), "$version", conf.WebVersion),
}
if siteConfig.BasePath != "" {
siteConfig.BasePath = utils.FixAndCleanPath(siteConfig.BasePath)
}
if siteConfig.Cdn == "" {
siteConfig.Cdn = siteConfig.BasePath
siteConfig.Cdn = strings.TrimSuffix(siteConfig.BasePath, "/")
}
return siteConfig
}