Kubernetes nginx ingress adds internal port

4/17/2019

I have a docker image with Nginx serving a static site. The site is served from a folder, lets call it "folder". When I request http://mydomain/folder/ it works. However when I request http://mydomain/folder it redirects to http://mydomain:8080/folder which is the internal port used by the container. How can I prevent my ingress controller from adding the port?

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  generation: 1
  labels:
    app.kubernetes.io/instance: administration-env
  name: administration-env-erst-env
  namespace: default
  resourceVersion: "71710149"
  selfLink: /apis/extensions/v1beta1/namespaces/default/ingresses/administration-env-erst-env
  uid: c89014d2-60fe-11e9-8a63-000d3a2cc488
spec:
  rules:
  - host: mydomain
    http:
      paths:
      - backend:
          serviceName: administration
          servicePort: 8080
        path: /administration
  tls:
  - hosts:
    - mydomain
    secretName: some-tls-secret
status:
  loadBalancer:
    ingress:
    - ip: xx.xx.xx.xx
-- user672009
kubernetes
nginx

2 Answers

4/17/2019

if you are using nginx ingress you can do this like

nginx.ingress.kubernetes.io/configuration-snippet

for an nginx location block snippet

nginx.ingress.kubernetes.io/server-snippet

for a snippet in the nginx config service block

server-snippets: |
    location /foldername {
      proxy_pass http://yourdomain/folder/;
      proxy_set_header Upgrade $http_upgrade;
      proxy_http_version 1.1;
      proxy_set_header X-Forwarded-Host $http_host;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_set_header Host $host;
      proxy_set_header Connection "upgrade";
      proxy_cache_bypass $http_upgrade;
      }
-- Harsh Manvar
Source: StackOverflow

4/17/2019

you can try as a workaround adding a proxy pass in your nginx.conf

something like:

location /folder {
  proxy_pass http://mydomain/folder/;
}
-- cperez08
Source: StackOverflow