apisix-ingress-controller: help request: Invalid FORWARDED_PORT header

Description

Hi,

I’m using apisix and I have a problem with the header FORWARDED_PORT.

  • The original request is: GET https://my.host (port 443)
  • There is a ApisixTls
  • There is a ApisixRoute pointing to a specific service at port 80 (internally 8080)
  • Apisix internally uses the port 9443

The request header sent to my internal service is:

  • FORWARDED_PROTO: https (ok)
  • FORWARDED_HOST: my.host (ok)
  • FORWARDED_PORT: 9443 (this should be the original 443, not the internally 9443 apisix port)

Using ingress instead of apisix is ok on my app. Do I need to add some configuration or plugin to propagate the right port?

I’m not sure if the issue should be a bug or support.

Environment

  • APISIX version (run apisix version): 3.4.1 (apisix helm chart 1.5.1)
  • Operating system (run uname -a): ubuntu 22.04
  • OpenResty / Nginx version (run openresty -V or nginx -V): nginx version: openresty/1.21.4.1

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

Temporary fixed with this plugin:

- name: serverless-pre-function
  enable: true
  config:
    phase: rewrite
    functions:
      - |
        return function()
          if ngx.var.scheme == "http" then
            ngx.req.set_header("X-FORWARDED-PORT", "80")
          elseif ngx.var.scheme == "https" then
            ngx.req.set_header("X-FORWARDED-PORT", "443")
          end
        end

@JoniJnm proxy-rewrite can rewrite request headers so you can use that to add x-forwarded-port as 80, but this is by no means the correct and feasible way.