From 3beb80c907d3c9583cc17b018bca2993b20e4604 Mon Sep 17 00:00:00 2001 From: yourchanges Date: Mon, 2 Feb 2015 15:37:03 +0800 Subject: [PATCH 1/7] add -reverseProxyServer="volume.xxx.com" to volume server try to fix #9 --- go/weed/server.go | 6 +++++- go/weed/volume.go | 7 +++++++ go/weed/weed_server/volume_server.go | 7 ++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/go/weed/server.go b/go/weed/server.go index 16b809c53..164c7e170 100644 --- a/go/weed/server.go +++ b/go/weed/server.go @@ -49,6 +49,7 @@ var cmdServer = &Command{ var ( serverIp = cmdServer.Flag.String("ip", "", "ip or server name") serverPublicIp = cmdServer.Flag.String("publicIp", "", "ip or server name") + reverseProxyServer = cmdServer.Flag.String("reverseProxyServer", "", "front-end reverse proxy server url , for replication > 000") serverBindIp = cmdServer.Flag.String("ip.bind", "0.0.0.0", "ip address to bind to") serverMaxCpu = cmdServer.Flag.Int("maxCpu", 0, "maximum number of CPUs. 0 means all available CPUs") serverTimeout = cmdServer.Flag.Int("idleTimeout", 10, "connection idle seconds") @@ -230,10 +231,13 @@ func runServer(cmd *Command, args []string) bool { *serverIp, *volumePort, *volumeAdminPort, *serverPublicIp, folders, maxCounts, *serverIp+":"+strconv.Itoa(*masterPort), *volumePulse, *serverDataCenter, *serverRack, - serverWhiteList, *volumeFixJpgOrientation, + serverWhiteList, *volumeFixJpgOrientation, *reverseProxyServer, ) glog.V(0).Infoln("Start Seaweed volume server", util.VERSION, "at", *serverIp+":"+strconv.Itoa(*volumePort)) + if *reverseProxyServer != "" { + glog.V(0).Infoln("The Seaweed volume server", util.VERSION, " is running behind the reverse proxy server", *reverseProxyServer) + } volumeListener, e := util.NewListener( *serverBindIp+":"+strconv.Itoa(*volumePort), time.Duration(*serverTimeout)*time.Second, diff --git a/go/weed/volume.go b/go/weed/volume.go index df1d603ac..a35c05afa 100644 --- a/go/weed/volume.go +++ b/go/weed/volume.go @@ -33,6 +33,7 @@ type VolumeServerOptions struct { rack *string whiteList []string fixJpgOrientation *bool + reverseProxyServer *string } func init() { @@ -49,6 +50,7 @@ func init() { v.dataCenter = cmdVolume.Flag.String("dataCenter", "", "current volume server's data center name") v.rack = cmdVolume.Flag.String("rack", "", "current volume server's rack name") v.fixJpgOrientation = cmdVolume.Flag.Bool("images.fix.orientation", true, "Adjust jpg orientation when uploading.") + v.reverseProxyServer = cmdVolume.Flag.String("reverseProxyServer", "", "front-end reverse proxy server url , for replication > 000") } var cmdVolume = &Command{ @@ -122,6 +124,7 @@ func runVolume(cmd *Command, args []string) bool { *v.master, *v.pulseSeconds, *v.dataCenter, *v.rack, v.whiteList, *v.fixJpgOrientation, + *v.reverseProxyServer, ) listeningAddress := *v.bindIp + ":" + strconv.Itoa(*v.port) @@ -151,5 +154,9 @@ func runVolume(cmd *Command, args []string) bool { if e := http.Serve(listener, publicMux); e != nil { glog.Fatalf("Volume server fail to serve: %v", e) } + + if *v.reverseProxyServer != "" { + glog.V(0).Infoln("The Seaweed volume server", util.VERSION, "is running behind the reverse proxy server", *v.reverseProxyServer) + } return true } diff --git a/go/weed/weed_server/volume_server.go b/go/weed/weed_server/volume_server.go index 8846c4794..f59833199 100644 --- a/go/weed/weed_server/volume_server.go +++ b/go/weed/weed_server/volume_server.go @@ -28,8 +28,13 @@ func NewVolumeServer(publicMux, adminMux *http.ServeMux, ip string, masterNode string, pulseSeconds int, dataCenter string, rack string, whiteList []string, - fixJpgOrientation bool) *VolumeServer { + fixJpgOrientation bool, + reverseProxyServer string) *VolumeServer { + publicUrl := publicIp + ":" + strconv.Itoa(port) + if reverseProxyServer != "" { + publicUrl = reverseProxyServer + } vs := &VolumeServer{ masterNode: masterNode, pulseSeconds: pulseSeconds, From 133181bbe4ef1676bb12d13574be4314df1b0ac2 Mon Sep 17 00:00:00 2001 From: yourchanges Date: Tue, 3 Feb 2015 13:54:44 +0800 Subject: [PATCH 2/7] add -reverseProxyServer="volume.xxx.com" to volume server try to fix #9 (reverted from commit 3beb80c907d3c9583cc17b018bca2993b20e4604) --- go/weed/server.go | 6 +----- go/weed/volume.go | 7 ------- go/weed/weed_server/volume_server.go | 7 +------ 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/go/weed/server.go b/go/weed/server.go index 164c7e170..16b809c53 100644 --- a/go/weed/server.go +++ b/go/weed/server.go @@ -49,7 +49,6 @@ var cmdServer = &Command{ var ( serverIp = cmdServer.Flag.String("ip", "", "ip or server name") serverPublicIp = cmdServer.Flag.String("publicIp", "", "ip or server name") - reverseProxyServer = cmdServer.Flag.String("reverseProxyServer", "", "front-end reverse proxy server url , for replication > 000") serverBindIp = cmdServer.Flag.String("ip.bind", "0.0.0.0", "ip address to bind to") serverMaxCpu = cmdServer.Flag.Int("maxCpu", 0, "maximum number of CPUs. 0 means all available CPUs") serverTimeout = cmdServer.Flag.Int("idleTimeout", 10, "connection idle seconds") @@ -231,13 +230,10 @@ func runServer(cmd *Command, args []string) bool { *serverIp, *volumePort, *volumeAdminPort, *serverPublicIp, folders, maxCounts, *serverIp+":"+strconv.Itoa(*masterPort), *volumePulse, *serverDataCenter, *serverRack, - serverWhiteList, *volumeFixJpgOrientation, *reverseProxyServer, + serverWhiteList, *volumeFixJpgOrientation, ) glog.V(0).Infoln("Start Seaweed volume server", util.VERSION, "at", *serverIp+":"+strconv.Itoa(*volumePort)) - if *reverseProxyServer != "" { - glog.V(0).Infoln("The Seaweed volume server", util.VERSION, " is running behind the reverse proxy server", *reverseProxyServer) - } volumeListener, e := util.NewListener( *serverBindIp+":"+strconv.Itoa(*volumePort), time.Duration(*serverTimeout)*time.Second, diff --git a/go/weed/volume.go b/go/weed/volume.go index a35c05afa..df1d603ac 100644 --- a/go/weed/volume.go +++ b/go/weed/volume.go @@ -33,7 +33,6 @@ type VolumeServerOptions struct { rack *string whiteList []string fixJpgOrientation *bool - reverseProxyServer *string } func init() { @@ -50,7 +49,6 @@ func init() { v.dataCenter = cmdVolume.Flag.String("dataCenter", "", "current volume server's data center name") v.rack = cmdVolume.Flag.String("rack", "", "current volume server's rack name") v.fixJpgOrientation = cmdVolume.Flag.Bool("images.fix.orientation", true, "Adjust jpg orientation when uploading.") - v.reverseProxyServer = cmdVolume.Flag.String("reverseProxyServer", "", "front-end reverse proxy server url , for replication > 000") } var cmdVolume = &Command{ @@ -124,7 +122,6 @@ func runVolume(cmd *Command, args []string) bool { *v.master, *v.pulseSeconds, *v.dataCenter, *v.rack, v.whiteList, *v.fixJpgOrientation, - *v.reverseProxyServer, ) listeningAddress := *v.bindIp + ":" + strconv.Itoa(*v.port) @@ -154,9 +151,5 @@ func runVolume(cmd *Command, args []string) bool { if e := http.Serve(listener, publicMux); e != nil { glog.Fatalf("Volume server fail to serve: %v", e) } - - if *v.reverseProxyServer != "" { - glog.V(0).Infoln("The Seaweed volume server", util.VERSION, "is running behind the reverse proxy server", *v.reverseProxyServer) - } return true } diff --git a/go/weed/weed_server/volume_server.go b/go/weed/weed_server/volume_server.go index f59833199..8846c4794 100644 --- a/go/weed/weed_server/volume_server.go +++ b/go/weed/weed_server/volume_server.go @@ -28,13 +28,8 @@ func NewVolumeServer(publicMux, adminMux *http.ServeMux, ip string, masterNode string, pulseSeconds int, dataCenter string, rack string, whiteList []string, - fixJpgOrientation bool, - reverseProxyServer string) *VolumeServer { - + fixJpgOrientation bool) *VolumeServer { publicUrl := publicIp + ":" + strconv.Itoa(port) - if reverseProxyServer != "" { - publicUrl = reverseProxyServer - } vs := &VolumeServer{ masterNode: masterNode, pulseSeconds: pulseSeconds, From 2df72001b2692407c8beb8a9441ea08672245c7a Mon Sep 17 00:00:00 2001 From: yourchanges Date: Thu, 12 Feb 2015 18:15:36 +0800 Subject: [PATCH 3/7] Move the redirect url to volume server's PublicUrl --- go/weed/weed_server/master_server_handlers_admin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/weed/weed_server/master_server_handlers_admin.go b/go/weed/weed_server/master_server_handlers_admin.go index 9d9880a6a..f81af6a2a 100644 --- a/go/weed/weed_server/master_server_handlers_admin.go +++ b/go/weed/weed_server/master_server_handlers_admin.go @@ -122,7 +122,7 @@ func (ms *MasterServer) redirectHandler(w http.ResponseWriter, r *http.Request) } machines := ms.Topo.Lookup("", volumeId) if machines != nil && len(machines) > 0 { - http.Redirect(w, r, "http://"+machines[0].Url()+r.URL.Path, http.StatusMovedPermanently) + http.Redirect(w, r, "http://"+machines[0].PublicUrl+r.URL.Path, http.StatusMovedPermanently) } else { writeJsonError(w, r, http.StatusNotFound, fmt.Errorf("volume id %d not found.", volumeId)) } From 2e0d0046c49e4da8bd59b436e57fcbc77056e4d7 Mon Sep 17 00:00:00 2001 From: yourchanges Date: Thu, 12 Feb 2015 18:35:29 +0800 Subject: [PATCH 4/7] Move the redirect url to volume server's PublicUrl (reverted from commit 2df72001b2692407c8beb8a9441ea08672245c7a) --- go/weed/weed_server/master_server_handlers_admin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/weed/weed_server/master_server_handlers_admin.go b/go/weed/weed_server/master_server_handlers_admin.go index f81af6a2a..9d9880a6a 100644 --- a/go/weed/weed_server/master_server_handlers_admin.go +++ b/go/weed/weed_server/master_server_handlers_admin.go @@ -122,7 +122,7 @@ func (ms *MasterServer) redirectHandler(w http.ResponseWriter, r *http.Request) } machines := ms.Topo.Lookup("", volumeId) if machines != nil && len(machines) > 0 { - http.Redirect(w, r, "http://"+machines[0].PublicUrl+r.URL.Path, http.StatusMovedPermanently) + http.Redirect(w, r, "http://"+machines[0].Url()+r.URL.Path, http.StatusMovedPermanently) } else { writeJsonError(w, r, http.StatusNotFound, fmt.Errorf("volume id %d not found.", volumeId)) } From 701bb9af19d9773896eb360c921a4c7fb6a2a2ea Mon Sep 17 00:00:00 2001 From: yourchanges Date: Thu, 12 Feb 2015 18:37:26 +0800 Subject: [PATCH 5/7] Move the redirect url perfer to volume server's PublicUrl --- go/topology/data_node.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/go/topology/data_node.go b/go/topology/data_node.go index 2d0a093cc..c7d04d953 100644 --- a/go/topology/data_node.go +++ b/go/topology/data_node.go @@ -87,6 +87,9 @@ func (dn *DataNode) MatchLocation(ip string, port int) bool { } func (dn *DataNode) Url() string { + if dn.PublicUrl != "" { + return dn.PublicUrl + } return dn.Ip + ":" + strconv.Itoa(dn.Port) } From 000c645d4569e1fc65c3248950106d702cdb4a10 Mon Sep 17 00:00:00 2001 From: yourchanges Date: Thu, 12 Feb 2015 18:44:45 +0800 Subject: [PATCH 6/7] Move the redirect url perfer to volume server's PublicUrl (reverted from commit 701bb9af19d9773896eb360c921a4c7fb6a2a2ea) --- go/topology/data_node.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/go/topology/data_node.go b/go/topology/data_node.go index c7d04d953..2d0a093cc 100644 --- a/go/topology/data_node.go +++ b/go/topology/data_node.go @@ -87,9 +87,6 @@ func (dn *DataNode) MatchLocation(ip string, port int) bool { } func (dn *DataNode) Url() string { - if dn.PublicUrl != "" { - return dn.PublicUrl - } return dn.Ip + ":" + strconv.Itoa(dn.Port) } From 7e0c080581ba48547f1746518a8b101e705b7c62 Mon Sep 17 00:00:00 2001 From: yourchanges Date: Thu, 12 Feb 2015 18:46:56 +0800 Subject: [PATCH 7/7] Move the redirect url perfer to volume server's PublicUrl --- go/weed/weed_server/master_server_handlers_admin.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/go/weed/weed_server/master_server_handlers_admin.go b/go/weed/weed_server/master_server_handlers_admin.go index 9d9880a6a..62605f331 100644 --- a/go/weed/weed_server/master_server_handlers_admin.go +++ b/go/weed/weed_server/master_server_handlers_admin.go @@ -122,7 +122,11 @@ func (ms *MasterServer) redirectHandler(w http.ResponseWriter, r *http.Request) } machines := ms.Topo.Lookup("", volumeId) if machines != nil && len(machines) > 0 { - http.Redirect(w, r, "http://"+machines[0].Url()+r.URL.Path, http.StatusMovedPermanently) + url := machines[0].PublicUrl + if url == "" { + url = machines[0].Url() + } + http.Redirect(w, r, "http://"+url+r.URL.Path, http.StatusMovedPermanently) } else { writeJsonError(w, r, http.StatusNotFound, fmt.Errorf("volume id %d not found.", volumeId)) }