mirror of
https://github.com/AlistGo/alist.git
synced 2025-06-06 02:21:06 +08:00
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:
@ -4,6 +4,7 @@ import (
|
||||
"github.com/alist-org/alist/v3/cmd/flags"
|
||||
"github.com/alist-org/alist/v3/internal/conf"
|
||||
"github.com/alist-org/alist/v3/internal/message"
|
||||
"github.com/alist-org/alist/v3/pkg/utils"
|
||||
"github.com/alist-org/alist/v3/server/common"
|
||||
"github.com/alist-org/alist/v3/server/handles"
|
||||
"github.com/alist-org/alist/v3/server/middlewares"
|
||||
@ -12,21 +13,27 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Init(r *gin.Engine) {
|
||||
common.SecretKey = []byte(conf.Conf.JwtSecret)
|
||||
Cors(r)
|
||||
r.Use(middlewares.StoragesLoaded)
|
||||
if conf.Conf.MaxConnections > 0 {
|
||||
r.Use(middlewares.MaxAllowed(conf.Conf.MaxConnections))
|
||||
func Init(e *gin.Engine) {
|
||||
if !utils.SliceContains([]string{"", "/"}, conf.URL.Path) {
|
||||
e.GET("/", func(c *gin.Context) {
|
||||
c.Redirect(302, conf.URL.Path)
|
||||
})
|
||||
}
|
||||
WebDav(r.Group("/dav"))
|
||||
g := e.Group(conf.URL.Path)
|
||||
common.SecretKey = []byte(conf.Conf.JwtSecret)
|
||||
Cors(g)
|
||||
g.Use(middlewares.StoragesLoaded)
|
||||
if conf.Conf.MaxConnections > 0 {
|
||||
g.Use(middlewares.MaxAllowed(conf.Conf.MaxConnections))
|
||||
}
|
||||
WebDav(g.Group("/dav"))
|
||||
|
||||
r.GET("/favicon.ico", handles.Favicon)
|
||||
r.GET("/i/:link_name", handles.Plist)
|
||||
r.GET("/d/*path", middlewares.Down, handles.Down)
|
||||
r.GET("/p/*path", middlewares.Down, handles.Proxy)
|
||||
g.GET("/favicon.ico", handles.Favicon)
|
||||
g.GET("/i/:link_name", handles.Plist)
|
||||
g.GET("/d/*path", middlewares.Down, handles.Down)
|
||||
g.GET("/p/*path", middlewares.Down, handles.Proxy)
|
||||
|
||||
api := r.Group("/api")
|
||||
api := g.Group("/api")
|
||||
auth := api.Group("", middlewares.Auth)
|
||||
|
||||
api.POST("/auth/login", handles.Login)
|
||||
@ -46,9 +53,11 @@ func Init(r *gin.Engine) {
|
||||
_fs(auth.Group("/fs"))
|
||||
admin(auth.Group("/admin", middlewares.AuthAdmin))
|
||||
if flags.Dev {
|
||||
dev(r.Group("/dev"))
|
||||
dev(g.Group("/dev"))
|
||||
}
|
||||
static.Static(r)
|
||||
static.Static(g, func(handlers ...gin.HandlerFunc) {
|
||||
e.NoRoute(handlers...)
|
||||
})
|
||||
}
|
||||
|
||||
func admin(g *gin.RouterGroup) {
|
||||
@ -124,10 +133,9 @@ func _fs(g *gin.RouterGroup) {
|
||||
g.POST("/add_qbit", handles.AddQbittorrent)
|
||||
}
|
||||
|
||||
func Cors(r *gin.Engine) {
|
||||
func Cors(r *gin.RouterGroup) {
|
||||
config := cors.DefaultConfig()
|
||||
config.AllowAllOrigins = true
|
||||
//config.AllowHeaders = append(config.AllowHeaders, "Authorization", "range", "File-Path", "As-Task", "Password")
|
||||
config.AllowHeaders = []string{"*"}
|
||||
config.AllowMethods = []string{"*"}
|
||||
r.Use(cors.New(config))
|
||||
|
Reference in New Issue
Block a user