Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2359 from thedadams/proxy-set-host-header
Browse files Browse the repository at this point in the history
Set the Host header in the nginx router config
  • Loading branch information
thedadams authored Nov 22, 2023
2 parents 3ff4592 + 7a03828 commit 62927ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions pkg/controller/appdefinition/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ func toNginxConf(routerName string, router v1.Router) (string, string) {
buf.WriteString(route.TargetServiceName)
buf.WriteString(":")
buf.WriteString(strconv.Itoa(port))
buf.WriteString(";\n}\n")
buf.WriteString(";\n proxy_set_header X-Forwarded-Host $http_host;")
buf.WriteString("\n}\n")
if route.PathType == v1.PathTypePrefix && !strings.HasSuffix(route.Path, "/") {
buf.WriteString("location ")
buf.WriteString(route.Path)
Expand All @@ -194,7 +195,8 @@ func toNginxConf(routerName string, router v1.Router) (string, string) {
buf.WriteString(route.TargetServiceName)
buf.WriteString(":")
buf.WriteString(strconv.Itoa(port))
buf.WriteString(";\n}\n")
buf.WriteString(";\n proxy_set_header X-Forwarded-Host $http_host;")
buf.WriteString("\n}\n")
}
if route.PathType == v1.PathTypePrefix && route.Path == "/" {
buf.WriteString("location ")
Expand All @@ -204,7 +206,8 @@ func toNginxConf(routerName string, router v1.Router) (string, string) {
buf.WriteString(route.TargetServiceName)
buf.WriteString(":")
buf.WriteString(strconv.Itoa(port))
buf.WriteString(";\n}\n")
buf.WriteString(";\n proxy_set_header X-Forwarded-Host $http_host;")
buf.WriteString("\n}\n")
}
}
buf.WriteString("}\n")
Expand Down
7 changes: 5 additions & 2 deletions pkg/controller/appdefinition/testdata/router/expected.golden
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ spec:
operator: Exists
volumes:
- configMap:
name: router-name-5f5b2f6b
name: router-name-e9cec3df
name: conf
status: {}

Expand All @@ -78,18 +78,21 @@ data:
listen 8080;
location = /foo {
proxy_pass http://foo-target:80;
proxy_set_header X-Forwarded-Host $http_host;
}
location = /zzzz {
proxy_pass http://zzz-target:80;
proxy_set_header X-Forwarded-Host $http_host;
}
location /zzzz/ {
proxy_pass http://zzz-target:80;
proxy_set_header X-Forwarded-Host $http_host;
}
}
kind: ConfigMap
metadata:
creationTimestamp: null
name: router-name-5f5b2f6b
name: router-name-e9cec3df
namespace: app-created-namespace

---
Expand Down

0 comments on commit 62927ea

Please sign in to comment.