Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traefik can not modify host header #5966

Closed
sifksky opened this issue Dec 9, 2019 · 2 comments
Closed

Traefik can not modify host header #5966

sifksky opened this issue Dec 9, 2019 · 2 comments

Comments

@sifksky
Copy link

sifksky commented Dec 9, 2019

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 ?

@traefiker
Copy link
Contributor

Hi! I'm Træfiker 🤖 the bot in charge of communication regulation.

Thanks for your interest in Traefik!

We dedicate the issue tracker to bug reports and feature requests only. My advanced AI has spotted that your issue might be a configuration problem or relates to something that doesn't look like a bug.

To confirm this, please join our Community Forum and reach out to us on the Traefik section.

In case I'm wrong (well, that would be embarrassing 😅), my developers will re-open the issue and fix me!

In the meantime, you can double check Traefik's documentation.

@sifksky sifksky changed the title Traefik can not add host header Traefik can not modify host header Dec 9, 2019
@traefik traefik locked and limited conversation to collaborators Jan 15, 2020
@traefiker traefiker added this to the 2.2 milestone Mar 17, 2020
@traefiker
Copy link
Contributor

Closed by #6502.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants