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

相关推荐
破刺不会编程44 分钟前
socket编程UDP
linux·运维·服务器·网络·c++·网络协议·udp
ayaya_mana2 小时前
Nginx性能优化与安全配置:打造高性能Web服务器
运维·nginx·安全·性能优化
我不要放纵8 小时前
docker
运维·docker·容器
morliz子轩8 小时前
基于WSL搭建Ubuntu 22.04.x LTS开发环境
linux·运维·ubuntu
BJ_Bonree8 小时前
数智先锋 | 告别运维黑盒!豪鹏科技×Bonree ONE构建全栈智能可观测体系
运维·科技
Janspran9 小时前
嵌入式linux学习 -- 进程和线程
linux·运维·学习
Cosmoshhhyyy9 小时前
linux远程部署dify和mac本地部署dify
linux·运维·macos
路多辛11 小时前
Debian新一代的APT软件源配置文件格式DEB822详解
linux·运维·ubuntu·debian
油丶酸萝卜别吃12 小时前
nginx配置代理服务器
运维·网络·nginx
maomao17131412 小时前
Jenkins 环境部署
运维·jenkins