0

We had scheme

 ELB => (Nginx proxy => Nodejs)containers

now we want to use kubernetes and nginx ingress

 ELB => Nginx Ingress (Load Balancer) => (Nginx proxy => Nodejs)pod

part of nginx proxy vhost config:

include /etc/nginx/redirect-map-domainb.conf;
include /etc/nginx/redirect-map-domaina.conf;
 server {
     listen 80;
     listen [::]:80;
     server_name domainb www.domainb;
     if ( $redirect_domainb ) {
         return 301 https://domaina$redirect_uri_domainb;
     }
     location / {
         return 301 https://domaina/en/company; } }

 server {
     listen 80;
     listen [::]:80;
     server_name domaina www.domaina;
     if ( $redirect_uri_domaina ) {
         return 301 https://domaina$redirect_uri_domaina;
     }
     location / {
         return 301 https://domaina/de/mobile; } }

 server {
     listen 1443;
     listen [::]:1443;
     server_name _;
     location /health_check {
         proxy_pass http://localhost:8000/ping;
         access_log off; }   }

 server {
     listen 443;
     listen [::]:443;
     server_name domaina www.domaina;
     if ( $redirect_uri_domaina) {
        return 301 https://domaina$redirect_uri_domaina;
     }
     root /app/dist;
       index index.html index.htm index.nginx-debian.html;
       access_log  /var/log/access.log logstash;
       error_log   /var/log/error.log;

     location / {
       proxy_pass http://localhost:8000;
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection 'upgrade';
       proxy_set_header Host $host;
       proxy_cache_bypass $http_upgrade;
     }

service yaml:

 apiVersion: v1
    kind: Service
    metadata:
      name: web
      annotations: {}
      labels:
        app: web
    spec:
      ports:
      - name: http
        port: 80
        targetPort: 80
      - name: https
        port: 443
        targetPort: 443
      selector:
        app: web
      type: ClusterIP

part of deployment yaml:

ports:
    - name: nginxhttp
      containerPort: http
    - name: nginxhttps
      containerPort: https

part ingres controller yaml:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
    annotations:
      nginx.ingress.kubernetes.io/rewrite-target: /

    name: dev-ingress
    namespace: default
spec:
  rules:
  - host: domaina
    http:
      paths:
      - backend:
          serviceName: web
          servicePort: 443
  - host: domainb
    http:
      paths:
      - backend:
          serviceName: web
          servicePort: 80

we installed nginx ingress with helm part of values file

service:
    annotations:
       service.beta.kubernetes.io/aws-load-balancer-backend-protocol: http
       service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: "3600"
       service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: '*'
       service.beta.kubernetes.io/aws-load-balancer-ssl-cert: arn:aws:acm:eu-west-1:565638931841:certificate/2222...
       service.beta.kubernetes.io/aws-load-balancer-ssl-ports: https


  targetPorts:
      http: http
      https: https

  type: LoadBalancer

we got error plain HTTP request was sent to HTTPS port how to route to nginx proxy vhost port from ingress? to make work redirect from http://domaina to https://domaina.

Community
  • 1
  • 1
marc345
  • 26
  • 4
  • Have you tried this article https://medium.com/store2be-tech/kubernetes-redirect-http-to-https-with-elb-and-the-nginx-ingress-controller-911c3f4f605 , that was given at this topic? https://stackoverflow.com/questions/51882079/kubernetes-http-to-https-redirect-on-aws-with-elb-terminating-ssl – Vit Sep 27 '18 at 15:43
  • Thanks for answer, the problem is if I use ingress.kubernetes.io/force-ssl-redirect annotation I will get 2 redirects 307 and then 301 redirect which is not good for our seo, – marc345 Sep 27 '18 at 18:06

0 Answers0