apache / apisix

The Cloud-Native API Gateway
https://apisix.apache.org/blog/
Apache License 2.0
14.48k stars 2.52k forks source link

bug: http2 not working #11543

Closed jialechan closed 1 month ago

jialechan commented 2 months ago

Current Behavior

Install apisix by helm, apisix's http2 not working by default

Expected Behavior

apisix's http2 should working by default

Error Logs

No response

Steps to Reproduce

  1. install apisix by helm image

  2. Get the application URL image

  3. test by curl image

Environment

kayx23 commented 2 months ago

It looks like the connection is established but there isn't a route at the path you requested 🤔

jialechan commented 2 months ago

It looks like the connection is established but there isn't a route at the path you requested 🤔

@kayx23 Thank you for your reply. I have done it again using the following method.

step one: Install by helm and get ip/port

image

stop two: create httpbin deployment and svc; create apisixroute;

apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpbin
  labels:
    app: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: httpbin
  template:
    metadata:
      labels:
        app: httpbin
    spec:
      containers:
      - name: httpbin
        image: kennethreitz/httpbin:latest
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: httpbin
spec:
  selector:
    app: httpbin
  ports:
    - name: httpbin
      protocol: TCP
      port: 80
      targetPort: 80
---
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
  name: httpbin
  namespace: default
spec:
  http:
    - backends:
        - serviceName: httpbin
          servicePort: 80
      match:
        paths:
          - /*
      name: route1

step three: check by curl use http2

image Not working, expected to be http2, resulting in http1.1

kayx23 commented 2 months ago

🤔 I am not sure at the moment but can confirm this behaviour is reproducible and does not have anything to do with the installation method.

jialechan commented 2 months ago

🤔 I am not sure at the moment but can confirm this behaviour is reproducible and does not have anything to do with the installation method.

Apisix should enable http2 by default(https://github.com/apache/apisix/issues/8989), but I cannot reproduce this feature and I don't know where the problem lies. 😭

shreemaan-abhishek commented 1 month ago

@jialechan maybe this issue is because the httpbin server doesn't support http2?

jialechan commented 1 month ago

@jialechan maybe this issue is because the httpbin server doesn't support http2?

@shreemaan-abhishek Thank you for your reply. I replace httpbin to something support http2, but it is not working too:

Step 1: create apisix

helm install apisix apisix/apisix --create-namespace --namespace ingress-apisix --set etcd.persistence.size=20Gi --set ingress-controller.enabled=true --set etcd.persistence.storageClass=alicloud-disk-essd

image

Step 2: create test service

apiVersion: v1
kind: Endpoints
metadata:
  name: my-test
subsets:
- addresses:
  - ip: 139.162.123.134 # nghttp2.org
  ports:
  - name: my-test
    port: 80
    protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  name: my-test
spec:
  ports:
  - name: my-test
    port: 80
    protocol: TCP
---
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
  name: my-test
  namespace: default
spec:
  http:
    - backends:
        - serviceName: my-test
          servicePort: 80
      match:
        paths:
          - /*
      name: route1

Step 3: test result image

It seems that http2 can be used to access the service directly, but it cannot be used after forwarding through apisix.

shreemaan-abhishek commented 1 month ago

can you confirm if http2 is enabled? https://github.com/apache/apisix-helm-chart/blob/38ed5919ecf49d84230b123b5551bf8c782398ea/charts/apisix/templates/configmap.yaml#L76

jialechan commented 1 month ago

can you confirm if http2 is enabled? https://github.com/apache/apisix-helm-chart/blob/38ed5919ecf49d84230b123b5551bf8c782398ea/charts/apisix/templates/configmap.yaml#L76

@shreemaan-abhishek Thank you for your reply.

As shown in the figure, this is my configuration. It seems that http2 has been enabled. apisix also enable http2 by default.

image

jialechan commented 1 month ago

@shreemaan-abhishek Thank you for your reply.

i am try to deploy apisix by docker, and h2c not wokring too:

step one: setup apisix by docker

docker run -d --name apache-apisix \
  -p 9080:9080 \
  -e APISIX_STAND_ALONE=true \
  apache/apisix

stop two: setup route

docker exec -i apache-apisix sh -c 'cat > /usr/local/apisix/conf/apisix.yaml <<_EOC_
routes:
  -
    id: httpbin
    uri: /*
    upstream:
      nodes:
        "nghttp2.org": 1
      type: roundrobin
#END
_EOC_'

step three: test

curl -I --http2 http://localhost:9080
curl -I --http2 http://nghttp2.org

image

image

apisix h2c not working...

jialechan commented 1 month ago

I have identified the root cause of the issue. Currently, nginx(after 1.25) only supports http1.1 or http2 when using HTTP (without TLS configuration), and does not support upgrading from http1.1 to http2