Ingress-nginx中HTTPS的强制转发

文章目录

在使用aws 的NLB转发流量到ingress时,发现NLP上生成的转发配置不符合正常预期,如下图:

ingress-nginx service 配置如下:

bash 复制代码
apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: "60"
    service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled: "true"
    service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: ip
    service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing
    service.beta.kubernetes.io/aws-load-balancer-ssl-cert: xxxxxxxxxxxxx
    service.beta.kubernetes.io/aws-load-balancer-ssl-ports: https
    service.beta.kubernetes.io/aws-load-balancer-type: nlb
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.1
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  allocateLoadBalancerNodePorts: true
  loadBalancerClass: service.k8s.aws/nlb
  ports:
  - appProtocol: http
    name: http
    nodePort: 30587
    port: 80
    protocol: TCP
    targetPort: tohttps # 2443 端口
  - appProtocol: https
    name: https
    nodePort: 31999
    port: 443
    protocol: TCP
    targetPort: http
  selector:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
  type: LoadBalancer

到这里可以看到 配置是没有问题的, 80端口的流量确实是指到了tohttp端口(2443),但这个端口又是什么端口呢。 为什么会有这样一个设定呢。

接下来查看ingress-nginx服务对于2443的设定,

bash 复制代码
        server {
                listen 2443;
                return 308 https://$host$request_uri;
        }

这里可以看出,对于2443端口,是强制对访问做了https跳转。

通过查看ingress-nginx官方文档,得到如下结果: "如果为该入口启用了 TLS,则控制器默认会将 (308) 重定向到 HTTPS"。

如何关闭呢。 参考:https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#server-side-https-enforcement-through-redirect

相关推荐
朱皮皮呀10 小时前
HTTPS的工作过程
网络协议·http·https
Binary-Jeff10 小时前
一文读懂 HTTPS 协议及其工作流程
网络协议·web安全·http·https
七夜zippoe13 小时前
CANN Runtime任务描述序列化与持久化源码深度解码
大数据·运维·服务器·cann
Fcy64814 小时前
Linux下 进程(一)(冯诺依曼体系、操作系统、进程基本概念与基本操作)
linux·运维·服务器·进程
袁袁袁袁满14 小时前
Linux怎么查看最新下载的文件
linux·运维·服务器
代码游侠15 小时前
学习笔记——设备树基础
linux·运维·开发语言·单片机·算法
Harvey90315 小时前
通过 Helm 部署 Nginx 应用的完整标准化步骤
linux·运维·nginx·k8s
珠海西格电力科技16 小时前
微电网能量平衡理论的实现条件在不同场景下有哪些差异?
运维·服务器·网络·人工智能·云计算·智慧城市
释怀不想释怀16 小时前
Linux环境变量
linux·运维·服务器
zzzsde16 小时前
【Linux】进程(4):进程优先级&&调度队列
linux·运维·服务器