summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/reverseproxy
diff options
context:
space:
mode:
Diffstat (limited to 'modules/caddyhttp/reverseproxy')
-rw-r--r--modules/caddyhttp/reverseproxy/command.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/modules/caddyhttp/reverseproxy/command.go b/modules/caddyhttp/reverseproxy/command.go
index 1638d82..c47447f 100644
--- a/modules/caddyhttp/reverseproxy/command.go
+++ b/modules/caddyhttp/reverseproxy/command.go
@@ -36,7 +36,7 @@ func init() {
caddycmd.RegisterCommand(caddycmd.Command{
Name: "reverse-proxy",
Func: cmdReverseProxy,
- Usage: "[--from <addr>] [--to <addr>]",
+ Usage: "[--from <addr>] [--to <addr>] [--change-host-header]",
Short: "A quick and production-ready reverse proxy",
Long: `
A simple but production-ready reverse proxy. Useful for quick deployments,
@@ -46,11 +46,16 @@ Simply shuttles HTTP traffic from the --from address to the --to address.
If the --from address has a domain name, Caddy will attempt to serve the
proxy over HTTPS with a certificate.
+
+If --change-host-header is set, the Host header on the request will be modified
+from its original incoming value to the address of the upstream. (Otherwise, by
+default, all incoming headers are passed through unmodified.)
`,
Flags: func() *flag.FlagSet {
fs := flag.NewFlagSet("file-server", flag.ExitOnError)
- fs.String("from", "", "Address to receive traffic on")
- fs.String("to", "", "Upstream address to proxy traffic to")
+ fs.String("from", "", "Address on which to receive traffic")
+ fs.String("to", "", "Upstream address to which to to proxy traffic")
+ fs.Bool("change-host-header", false, "Set upstream Host header to address of upstream")
return fs
}(),
})
@@ -59,6 +64,7 @@ proxy over HTTPS with a certificate.
func cmdReverseProxy(fs caddycmd.Flags) (int, error) {
from := fs.String("from")
to := fs.String("to")
+ changeHost := fs.Bool("change-host-header")
if from == "" {
from = "localhost:" + httpcaddyfile.DefaultPort
@@ -97,13 +103,16 @@ func cmdReverseProxy(fs caddycmd.Flags) (int, error) {
handler := Handler{
TransportRaw: caddyconfig.JSONModuleObject(ht, "protocol", "http", nil),
Upstreams: UpstreamPool{{Dial: toURL.Host}},
- Headers: &headers.Handler{
+ }
+
+ if changeHost {
+ handler.Headers = &headers.Handler{
Request: &headers.HeaderOps{
Set: http.Header{
- "Host": []string{"{http.reverse_proxy.upstream.host}"},
+ "Host": []string{"{http.reverse_proxy.upstream.hostport}"},
},
},
- },
+ }
}
route := caddyhttp.Route{