apache / apisix

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

help request: How to set http redirect to https in the host/domain level? #8861

Closed SpecialYang closed 11 months ago

SpecialYang commented 1 year ago

Description

I'm tired of doing http redirect to https for every route. Can we just open this redirect on the host level?

Just like istio does.

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: my-gateway
  namespace: some-config-namespace
spec:
  selector:
    app: my-gateway-controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - uk.bookinfo.com
    tls:
      httpsRedirect: true # sends 301 redirect for http requests
  - port:
      number: 443
      name: https-443
      protocol: HTTPS
    hosts:
    - uk.bookinfo.com

Environment

tokers commented 1 year ago

@SpecialYang We never say "host level" in APISIX, you need to convert the concept to the APISIX terms like a Service, a Route, combining with your business.

E.g., if you use a Service in APISIX to manage all routes in the same host, you may need to enable the redirect plugin in this Service.

SpecialYang commented 1 year ago

The Service defined in the APISIX looks like it combines more than one routes but must be forwarded for only one upstream. In micro-services case, routes under the same host can be forwarded for more micro-services. I think the Service concept is limited and can not solve my issue.

tokers commented 1 year ago

The Service defined in the APISIX looks like it combines more than one routes but must be forwarded for only one upstream. In micro-services case, routes under the same host can be forwarded for more micro-services. I think the Service concept is limited and can not solve my issue.

Not clear about your model. You may need to write some codes to implement your demands (with a plugin runner, or using the serverless plugin).

SpecialYang commented 1 year ago
example.com/app1 ->  upstream (app1)
example.com/app2 -> upstream (app2)
...
example.com/appn -> upstream (appn)

I hope I can set http redirect to https in one place which make the above all routes under the same host example.com redirect to https://example.com/app(x) when i call http://example.com/app(x).

tokers commented 1 year ago

Got it. I'm afraid that the existing APISIX plugins won't satisfy your need. Maybe you can use the serverless plugin to check the following things:

  1. If the host is example.com;
  2. If the scheme is HTTP;

If both the conditions are met, then redirect the requests, and constructing the Location header with HTTPS schema (be careful about the HTTPS port).

shreemaan-abhishek commented 1 year ago

@SpecialYang do you have any further updates/questions? If not please close this issue. Thanks.

github-actions[bot] commented 11 months ago

Due to lack of the reporter's response this issue has been labeled with "no response". It will be close in 3 days if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the dev@apisix.apache.org list. Thank you for your contributions.

github-actions[bot] commented 11 months ago

This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.