You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This change implements optional HTTP redirection to the TLS/HTTPS fromURL where ssl-proxy is serving TLS traffic. This makes it easy to redirect any traffic coming in at http://mysite:80 to https://mysite where ssl-proxy is serving TLS certificates. This closes#11. This feature always redirects HTTP traffic from port 80.
Copy file name to clipboardExpand all lines: main.go
+33-9Lines changed: 33 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,7 @@ package main
2
2
3
3
import (
4
4
"flag"
5
+
"fmt"
5
6
"log"
6
7
"net/http"
7
8
"net/url"
@@ -16,11 +17,12 @@ import (
16
17
)
17
18
18
19
var (
19
-
to=flag.String("to", "http://127.0.0.1:80", "the address and port for which to proxy requests to")
20
-
fromURL=flag.String("from", "127.0.0.1:4430", "the tcp address and port this proxy should listen for requests on")
21
-
certFile=flag.String("cert", "", "path to a tls certificate file. If not provided, ssl-proxy will generate one for you in ~/.ssl-proxy/")
22
-
keyFile=flag.String("key", "", "path to a private key file. If not provided, ssl-proxy will generate one for you in ~/.ssl-proxy/")
23
-
domain=flag.String("domain", "", "domain to mint letsencrypt certificates for. Usage of this parameter implies acceptance of the LetsEncrypt terms of service.")
20
+
to=flag.String("to", "http://127.0.0.1:80", "the address and port for which to proxy requests to")
21
+
fromURL=flag.String("from", "127.0.0.1:4430", "the tcp address and port this proxy should listen for requests on")
22
+
certFile=flag.String("cert", "", "path to a tls certificate file. If not provided, ssl-proxy will generate one for you in ~/.ssl-proxy/")
23
+
keyFile=flag.String("key", "", "path to a private key file. If not provided, ssl-proxy will generate one for you in ~/.ssl-proxy/")
24
+
domain=flag.String("domain", "", "domain to mint letsencrypt certificates for. Usage of this parameter implies acceptance of the LetsEncrypt terms of service.")
25
+
redirectHTTP=flag.Bool("redirectHTTP", false, "if true, redirects http requests from port 80 to https at your fromURL")
24
26
)
25
27
26
28
const (
@@ -84,9 +86,24 @@ func main() {
84
86
mux:=http.NewServeMux()
85
87
mux.Handle("/", p)
86
88
87
-
log.Printf("Proxying calls from https://%s (SSL/TLS) to %s", *fromURL, toURL)
89
+
log.Printf(green("Proxying calls from https://%s (SSL/TLS) to %s"), *fromURL, toURL)
88
90
89
-
// Determine if we should serve with autogenerated LetsEncrypt certificates or not
91
+
// Redirect http requests on port 80 to TLS port using https
0 commit comments