Hi Traefik:
I host a web static in AWS S3, so I use Externalname in k8s service.In order to access website from traefik to AWS S3, I must modify the host headers. When I use the add header middlewares, but the host can not change. If I use curl -H "Host: dev-cn-mercku-static-files.s3-website.cn-north-1.amazonaws.com.cn ", I can access the website successful. pls help.
AWS S3 Service
apiVersion: v1
kind: Service
metadata:
name: aws-s3
spec:
type: ExternalName
externalName: dev-cn-mercku-static-files.s3-website.cn-north-1.amazonaws.com.cn
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
http rule is :
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: httpingressroute
spec:
entryPoints:
- web
routes:
- match: Host(`kk.hyku.org`,`dev-cn-mercku-static-files.s3-website.cn-north-1.amazonaws.com.cn`)
kind: Rule
services:
- name: aws-s3
port: 80
middlewares:
- name: add-header
add-header:
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: add-header
spec:
headers:
customRequestHeaders:
Host: "dev-cn-mercku-static-files.s3-website.cn-north-1.amazonaws.com.cn"
X-Script-Name: "11111"
customResponseHeaders:
X-Custom-Response-Header: "22222"
curl -vvv -H "Host: dev-cn-mercku-static-files.s3-website.cn-north-1.amazonaws.com.cn " http://kk.hyku.org/assets/mercku_console_web/index.html
Result:
* Trying 10.70.1.34...
* TCP_NODELAY set
* Connected to kk.hyku.org (10.70.1.34) port 80 (#0)
> GET /assets/mercku_console_web/index.html HTTP/1.1
> Host: dev-cn-mercku-static-files.s3-website.cn-north-1.amazonaws.com.cn
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Cache-Control: max-age=30
< Content-Length: 672
< Content-Type: text/html
< Date: Mon, 09 Dec 2019 03:34:05 GMT
< Etag: "2e8e80498c9c06906700091fca894152"
< Last-Modified: Thu, 07 Nov 2019 02:43:21 GMT
< Server: AmazonS3
< X-Amz-Id-2: zdGWolqnYlL9vbk/yqnROvITKkozX1jWHfzfCYOkmjmotTCdZPXMmkILMp7RMayD+UEvs35TEgE=
< X-Amz-Meta-S3cmd-Attrs: atime:1573094589/ctime:1573094589/gid:1000/gname:jenkins/md5:2e8e80498c9c06906700091fca894152/mode:33188/mtime:1573094589/uid:1000/uname:jenkins
< X-Amz-Request-Id: E22CD3729392F8F7
< X-Custom-Response-Header: 22222
<
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>Mercku Console</title>
<link rel="shortcut icon" href="/favicon.ico"><link href="/static/css/index.6f9e4b35ae19602298249cb72540411b.css" rel="stylesheet"></head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
<script type="text/javascript" src="/static/js/axios.f432f9f264b4bc9ee091.js"></script><script type="text/javascript" src="/static/js/auth.538ad581331775de2585.js"></script><script type="text/javascript" src="/static/js/index.5d0fe7828c7e80e8898b.js"></script></body>
</html>
* Connection #0 to host kk.hyku.org left intact
curl -vvv http://kk.hyku.org/assets/mercku_console_web/index.html
Result
* Trying 10.70.1.34...
* TCP_NODELAY set
* Connected to kk.hyku.org (10.70.1.34) port 80 (#0)
> GET /assets/mercku_console_web/index.html HTTP/1.1
> Host: kk.hyku.org
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Content-Length: 358
< Content-Type: text/html; charset=utf-8
< Date: Mon, 09 Dec 2019 03:35:29 GMT
< Server: AmazonS3
< X-Amz-Id-2: yexj/Zm563gmgKP+INIwlFXarZNx87mdLPYNfn0FNogQhqVoXkj0Pu7wSZS+SEsb2co5JNOT9Ec=
< X-Amz-Request-Id: 4BEC686D03CB39E1
< X-Custom-Response-Header: 22222
<
<html>
<head><title>404 Not Found</title></head>
<body>
<h1>404 Not Found</h1>
<ul>
<li>Code: NoSuchBucket</li>
<li>Message: The specified bucket does not exist</li>
<li>BucketName: kk.hyku.org</li>
<li>RequestId: 4BEC686D03CB39E1</li>
<li>HostId: yexj/Zm563gmgKP+INIwlFXarZNx87mdLPYNfn0FNogQhqVoXkj0Pu7wSZS+SEsb2co5JNOT9Ec=</li>
</ul>
<hr/>
</body>
</html>
* Connection #0 to host kk.hyku.org left intact
Question: Why the Host header can not be changed ?
sifksky
December 10, 2019, 1:41am
2
Any one can help ? Thank you very much.
sifksky
December 11, 2019, 9:32am
4
Hi Traefik:
I read all traefik doc from headers and I test all parameter from headers. I still can not modify the Host header. But I can modify the header "X-Forwarded-Host" from customRequestHeaders, can modify the header "User-Agent" from customResponseHeaders. I want to know, traefik whether
prohibit modification of host header ?
This is the header yaml
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: add-header
spec:
headers:
customRequestHeaders:
Host: "dev-cn-mercku-static-files.s3-website.cn-north-1.amazonaws.com.cn"
X-Forwarded-Host: "dev-cn-mercku-static-files.s3-website.cn-north-1.amazonaws.com.cn"
customResponseHeaders:
User-Agent: "bbbbbb"
This is the curl result
sifksky@sifksky-Office:~$ curl -vvv http://kk.hyku.org
* Rebuilt URL to: http://kk.hyku.org/
* Trying 10.70.1.34...
* TCP_NODELAY set
* Connected to kk.hyku.org (10.70.1.34) port 80 (#0)
> GET / HTTP/1.1
> Host: kk.hyku.org
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Length: 487
< Content-Type: text/plain; charset=utf-8
< Date: Wed, 11 Dec 2019 09:27:32 GMT
< User-Agent: bbbbbb
<
Hostname: whoami-8457d7cd94-872cp
IP: 127.0.0.1
IP: 10.244.0.73
RemoteAddr: 10.244.0.94:54382
GET / HTTP/1.1
Host: kk.hyku.org
User-Agent: curl/7.58.0
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 10.70.1.5
X-Forwarded-Host: dev-cn-mercku-static-files.s3-website.cn-north-1.amazonaws.com.cn
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Server: traefik-xbqwk
X-Instana-L: 1
X-Instana-S: 59d830a6c704be06
X-Instana-T: 5015f4c577283c64
X-Real-Ip: 10.70.1.5
* Connection #0 to host kk.hyku.org left intact
This is console pic
ldez
December 11, 2019, 9:49am
5
Hello,
could you explain precisely why you need to change the Host header?
sifksky
December 12, 2019, 3:15am
6
Hi, thank you reply to me. Because the front of my system is on AWS S3 with static html, the backend of website is in k8s pod. When I access https://kk.hyku.org , traefik will redirect to AWS S3 and when I access the https://kk.hyku.org/v1 , it will redirect to k8s pod.
If I access to AWS S3, must use the domain "dev-cn-mercku-static-files.s3-website.cn-north-1.amazonaws.com.cn ", otherwise will return:
* Rebuilt URL to: http://kk.hyku.org/
* Trying 10.70.1.34...
* TCP_NODELAY set
* Connected to kk.hyku.org (10.70.1.34) port 80 (#0)
> GET / HTTP/1.1
> Host: kk.hyku.org
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Content-Length: 358
< Content-Type: text/html; charset=utf-8
< Date: Thu, 12 Dec 2019 03:29:43 GMT
< Server: AmazonS3
< User-Agent: bbbbbb
< X-Amz-Id-2: DvmCmb/07ThCpbJ6htGa14/JEQM5UM7UliurNiVVoHeTqcD2NXdAiBJp+HYrHkDS+ARQzEAbuWI=
< X-Amz-Request-Id: 6E49DAD1BA05CA25
<
<html>
<head><title>404 Not Found</title></head>
<body>
<h1>404 Not Found</h1>
<ul>
<li>Code: NoSuchBucket</li>
<li>Message: The specified bucket does not exist</li>
<li>BucketName: kk.hyku.org</li>
<li>RequestId: 6E49DAD1BA05CA25</li>
<li>HostId: DvmCmb/07ThCpbJ6htGa14/JEQM5UM7UliurNiVVoHeTqcD2NXdAiBJp+HYrHkDS+ARQzEAbuWI=</li>
</ul>
<hr/>
</body>
</html>
* Connection #0 to host kk.hyku.org left intact
I checked, the ExternalName of k8s service is only a cname to “dev-cn-mercku-static-files.s3-website.cn-north-1.amazonaws.com.cn ”, the AWS check the host is kk.hyku.org , no match "dev-cn-mercku-static-files.s3-website.cn-north-1.amazonaws.com.cn ".
So I need traefik modify the host from kk.hyku.org to dev-cn-mercku-static-files.s3-website.cn-north-1.amazonaws.com.cn . Such as curl -vvv -H "Host: xxxxx" https://kk.hyku.org .
Before I use nginx, I must config the "proxy_set_header Host dev-cn-mercku-static-files.s3-website.cn-north-1.amazonaws.com.cn ;"
This is the aws_s3_svc:
apiVersion: v1
kind: Service
metadata:
name: aws-s3-http
spec:
type: ExternalName
externalName: dev-cn-mercku-static-files.s3-website.cn-north-1.amazonaws.com.cn
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
sifksky
December 12, 2019, 3:20am
8
In other words, how does traefik access static resources in the external domain? http or https
sifksky
December 16, 2019, 1:22am
9
Any one can help me, thank you very much !
Hi guys, have the same issue looks like, need to pass specific host header to upstream servers, is there any possibility to do that with traefik?
Hello, I have the same issue looks like, need to change host header to k8s servers, is there any possibility to do that with traefik?