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

相关推荐
也许,也会2 分钟前
PLC NCU1750与PLC1200s7通讯
运维·服务器
MoloXuanhe35 分钟前
[TryHackMe]Wordpress: CVE-2021-29447(wp漏洞利用-SSRF+WpGetShell)
运维·网络·安全·tryhackme·thm
wanhengidc1 小时前
网页版的云手机都有哪些优势?
运维·网络·安全·游戏·智能手机
2418ly2 小时前
docker常用命令
运维·docker·容器
2501_916008892 小时前
uni-app iOS 日志与崩溃分析全流程 多工具协作的实战指南
android·ios·小程序·https·uni-app·iphone·webview
Nazi63 小时前
sealos部署k8s
运维·kubernetes·k8s
白鹭4 小时前
MySQL主从复制进阶(GTID复制,半同步复制)
linux·运维·数据库·mysql·集群
Dobby_054 小时前
【Linux】网络安全管理:SELinux 和 防火墙联合使用 | Redhat
linux·运维·云原生·防火墙·selinux
cetcht88885 小时前
安徽某能源企业积极推进运维智能化转型,引入高压配电房机器人巡检系统
运维·人工智能·物联网·机器人·能源
wheeldown5 小时前
【Linux】Linux进程状态和僵尸进程:一篇看懂“进程在忙啥”
linux·运维·服务器·进程