1

I am trying to set up an Ingress controller on Microk8s to host a react (NextJS) app.

The pod and service are up and running, as well as reachable internally via machine.domain.eu:31111

My goal is to make this service available via machine.domain.eu/dev on the default port 80 using an nginx ingress controller:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
    - host: machine.domain.eu
      http:
        paths:
          - path: /dev(/|$)(.*)
            pathType: Prefix
            backend:
              service:
                name: web-svc
                port: 
                  number: 3000

If I issue a curl command via curl machine.domain.eu/dev from the machine, where the node is running, I am getting back the desired html, although I cannot see, if assets are being loaded.

When switching back to my local machine opening my browser of choice and hit that http endpoint I do get a blank screen and all static assets 404. The index.html comes through fine, yet all the other resources are not found.

I've tried any number of combinations on the annotation to rewrite to /$1 /$2, while changing the path to - path: /dev/?(.*) but to no effect.

In other words: The document itself is loaded via http://machine.domain.eu/dev

Yet the assets, which should be loaded via http://machine.domain.eu/dev/_next/{....}

are actually being requested via:

http://machine.domain.eu/_next/{....}

What excactly am I doing wrong here?

Marco
  • 22,856
  • 9
  • 75
  • 124
  • The path can just be `/dev/` (or `/dev`, but you need to be careful if something else has `/developer`, e.g.). Your app/service may need to set a global base path of `dev/`, so all its routes start with `dev/`: `dev/controller/action`, for example. Setting a base path allows you to change it in one place. I'm not sure what that's called in next.js – ps2goat Dec 17 '20 at 16:10
  • Looks like [this](https://nextjs.org/docs/api-reference/next.config.js/basepath) may be it – ps2goat Dec 17 '20 at 16:11
  • I'm already doing that. Also assetPrefix, but it does not have any effect. Neither locally nor remote. I'm calling it a day and will investigate again tomorrow. – Marco Dec 17 '20 at 17:13

0 Answers0