From a566bfc6e1b25c262c3eb20cd9a8a2ef7a5f5392 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 28 Jul 2020 08:47:24 -0700 Subject: [PATCH] s3: use bucket in the domain fix https://github.com/chrislusf/seaweedfs/issues/1405 --- weed/command/s3.go | 1 + weed/s3api/s3api_server.go | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/weed/command/s3.go b/weed/command/s3.go index 7ebd4fab0..92f13673c 100644 --- a/weed/command/s3.go +++ b/weed/command/s3.go @@ -151,6 +151,7 @@ func (s3opt *S3Options) startS3Server() bool { _, s3ApiServer_err := s3api.NewS3ApiServer(router, &s3api.S3ApiServerOption{ Filer: *s3opt.filer, + Port: *s3opt.port, FilerGrpcAddress: filerGrpcAddress, Config: *s3opt.config, DomainName: *s3opt.domainName, diff --git a/weed/s3api/s3api_server.go b/weed/s3api/s3api_server.go index 773094a5f..010958245 100644 --- a/weed/s3api/s3api_server.go +++ b/weed/s3api/s3api_server.go @@ -1,6 +1,7 @@ package s3api import ( + "fmt" "net/http" "github.com/gorilla/mux" @@ -9,6 +10,7 @@ import ( type S3ApiServerOption struct { Filer string + Port int FilerGrpcAddress string Config string DomainName string @@ -37,7 +39,10 @@ func (s3a *S3ApiServer) registerRouter(router *mux.Router) { apiRouter := router.PathPrefix("/").Subrouter() var routers []*mux.Router if s3a.option.DomainName != "" { - routers = append(routers, apiRouter.Host("{bucket:.+}."+s3a.option.DomainName).Subrouter()) + routers = append(routers, apiRouter.Host( + fmt.Sprintf("%s.%s:%d", "{bucket:.+}", s3a.option.DomainName, s3a.option.Port)).Subrouter()) + routers = append(routers, apiRouter.Host( + fmt.Sprintf("%s.%s", "{bucket:.+}", s3a.option.DomainName)).Subrouter()) } routers = append(routers, apiRouter.PathPrefix("/{bucket}").Subrouter())