apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx
data:
  # Adding new entries here will make them appear as files in the deployment.
  nginx.conf: |
    worker_processes 5;

    events {
    }

    http {
      # Certs for all SSL server_names.
      ssl_certificate     /certs/tls.crt;
      ssl_certificate_key /certs/tls.key;
      ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
      ssl_ciphers         HIGH:!aNULL:!MD5;

      # This is the main site.
      #
      # Upgrade HTTP to HTTPS.
      server {
        server_name kubernetes.io;
        listen 80;
        return 301 https://$server_name$request_uri;
      }
      # Handle HTTPS.
      server {
        server_name kubernetes.io;
        listen 443 ssl;

        if ($arg_go-get = "1") {
          # This is a go-get operation.
          # Send any file in any repo to static content.
          rewrite ^/([^/]*)(/.*)?$  /_golang-go-get/$1.html;
        }

        location /_golang-go-get {
          # Serve static content.
          alias /www/golang;
        }

        location /_healthz {
          add_header Content-Type text/plain;
          return 200 'ok';
        }

        # Proxy to the real site.
        # We set the host to the vanity domain `kubernetes.io` but proxy to
        # `kubernetes.github.io` so that any relative redirects it generates on
        # the github side are to the vanity domain.  DNS points the vanity
        # domain at this nginx.
        location / {
          proxy_set_header Host kubernetes.io;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_next_upstream error timeout http_500 http_502 http_503 http_504;
          proxy_pass https://kubernetes.github.io;
        }
      }
      # Vanity names.
      server {
        server_name k8s.io kubernet.es;
        listen 80;
        listen 443 ssl;
        return 301 https://kubernetes.io$request_uri;
      }

      #
      # Vanity redirect rules.
      #

      server {
        server_name apt.kubernetes.io apt.k8s.io;
        listen 80;
        listen 443 ssl;

        rewrite ^/(.*)?$    https://packages.cloud.google.com/apt/$1 redirect;
      }

      server {
        server_name yum.kubernetes.io yum.k8s.io;
        listen 80;
        listen 443 ssl;

        rewrite ^/(.*)?$    https://packages.cloud.google.com/yum/$1 redirect;
      }

      server {
        server_name changelog.kubernetes.io changelog.k8s.io;
        listen 80;
        listen 443 ssl;

        rewrite ^/(.*)?$    https://github.com/kubernetes/kubernetes/releases/tag/$1 redirect;
      }
      server {
        server_name ci-test.kubernetes.io ci-test.k8s.io;
        listen 80;
        listen 443 ssl;

        # This is really not ideal, but there's no obvious way to browse GCS that handles directories and files.
        rewrite ^/$             https://console.developers.google.com/storage/browser/kubernetes-jenkins/logs redirect;
        # Things that look like builds should be viewed on Gubernator
        rewrite ^/(.*/\d+)/?$   https://k8s-gubernator.appspot.com/build/kubernetes-jenkins/logs/$1 redirect;
        rewrite ^/(.*)/$        https://console.developers.google.com/storage/browser/kubernetes-jenkins/logs/$1 redirect;
        rewrite ^/(.*)$         https://storage.cloud.google.com/kubernetes-jenkins/logs/$1 redirect;
      }
      server {
        server_name code.kubernetes.io code.k8s.io;
        listen 80;
        listen 443 ssl;

        rewrite ^/(.*)?$    https://github.com/kubernetes/kubernetes/tree/master/$1 redirect;
      }
      server {
        server_name dl.k8s.io dl.kubernetes.io;
        listen 80;
        listen 443 ssl;

        location / {
          # Don't require /release/ if you want to get at the Kubernetes release artifacts, the common case.
          rewrite ^/(v[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta)\.[0-9]+)?/.*)$   https://storage.googleapis.com/kubernetes-release/release/$1 redirect;
          # Provide a convenient redirect for CI (continuous integration) artifacts as well, which live in a different bucket.
          rewrite ^/ci(-cross)?/?(.*)$              https://storage.googleapis.com/kubernetes-release-dev/ci$1/$2 redirect;
          rewrite ^/(.*)$                  https://storage.googleapis.com/kubernetes-release/$1 redirect;
        }
      }
      server {
        server_name docs.k8s.io docs.kubernetes.io;
        listen 80;
        listen 443 ssl;

        location / {
          rewrite ^/v[0-9]+\.[0-9]+(/.*)?$     http://kubernetes.io/docs$1   redirect; # legacy
          rewrite ^/(.*)$                      http://kubernetes.io/docs/$1  redirect;
        }
      }
      server {
        server_name examples.k8s.io examples.kubernetes.io;
        listen 80;
        listen 443 ssl;

        location / {
          rewrite ^/v([0-9]+\.[0-9]+)(/.*)?$    https://github.com/kubernetes/kubernetes/tree/release-$1/examples$2  redirect;
          rewrite ^/(.*)$                       https://github.com/kubernetes/kubernetes/tree/master/examples/$1     redirect;
        }
      }
      server {
        server_name feature.k8s.io features.k8s.io feature.kubernetes.io features.kubernetes.io;
        listen 80;
        listen 443 ssl;

        location / {
          rewrite ^/(.*)$  https://github.com/kubernetes/features/issues/$1 redirect;
        }
      }
      server {
        server_name get.k8s.io get.kubernetes.io;
        listen 80;
        # 443 is covered below.

        location / {
          root /www/get;
          index get-kube-insecure.sh;
        }
      }
      server {
        server_name get.k8s.io get.kubernetes.io;
        listen 443 ssl;
        # 80 is covered above.

        # Note that 'location =' is an exact match, no sub-URI's match.
        location = / {
          proxy_set_header Host raw.githubusercontent.com;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_next_upstream error timeout http_500 http_502 http_503 http_504;
          proxy_pass https://raw.githubusercontent.com/kubernetes/kubernetes/master/cluster/get-kube.sh;
        }
      }
      server {
        server_name go.k8s.io go.kubernetes.io;
        listen 80;
        listen 443 ssl;

        location / {
          rewrite ^/bounty$          https://github.com/kubernetes/kubernetes.github.io/issues?q=is%3Aopen+is%3Aissue+label%3ABounty redirect;
          rewrite ^/help-wanted$     https://github.com/kubernetes/kubernetes/labels/help-wanted redirect;
          rewrite ^/oncall$          https://storage.googleapis.com/kubernetes-jenkins/oncall.html;
          rewrite ^/partner-request$ https://docs.google.com/forms/d/e/1FAIpQLSdN1KtSKX2VAOPGABFlShkSd6CajQynoL4QCVtY0dj76MNDKg/viewform redirect;
          rewrite ^/start$           http://kubernetes.io/docs/getting-started-guides/ redirect;
        }
      }
      server {
        server_name issue.k8s.io issues.k8s.io issue.kubernetes.io issues.kubernetes.io;
        listen 80;
        listen 443 ssl;

        location / {
          rewrite ^/(.*)$              https://github.com/kubernetes/kubernetes/issues/$1 redirect;
        }
      }
      server {
        server_name pr.k8s.io prs.k8s.io pr.kubernetes.io prs.kubernetes.io;
        listen 80;
        listen 443 ssl;

        location / {
          rewrite ^/$                  https://github.com/kubernetes/kubernetes/pulls redirect;
          rewrite ^/(.*)$              https://github.com/kubernetes/kubernetes/pull/$1 redirect;
        }
      }
      server {
        server_name pr-test.kubernetes.io pr-test.k8s.io;
        listen 80;
        listen 443 ssl;

        rewrite ^/$       https://k8s-gubernator.appspot.com redirect;
        rewrite ^/(.*)$   https://k8s-gubernator.appspot.com/pr/$1 redirect;

      }
      server {
        server_name releases.k8s.io rel.k8s.io releases.kubernetes.io rel.kubernetes.io;
        listen 80;
        listen 443 ssl;

        location / {
          rewrite ^/$                  https://github.com/kubernetes/kubernetes/releases redirect;
          rewrite ^/([^/]*)(/.*)?$     https://github.com/kubernetes/kubernetes/tree/$1$2 redirect;
        }
      }
      server {
        server_name reviewable.kubernetes.io reviewable.k8s.io;
        listen 80;
        listen 443 ssl;

        rewrite ^/(.*)?$    https://reviewable.kubernetes.io/$1 redirect;
      }

      server {
        server_name testgrid.kubernetes.io testgrid.k8s.io;
        listen 80;
        listen 443 ssl;

        rewrite ^/(.*)?$    https://k8s-testgrid.appspot.com/$1 redirect;
      }
    }
