Strapi admin panel not routing correctly with Nginx Ingress

We are trying to host our frontend and our backend on the same domain.

Nuxt will be https://ourdomain.com/

Strapi will be https://ourdomain.com/api

Strapi admin panel will be https://ourdomain.com/api/admin

Currently Nuxt and Strapi API are working fine with
/api/leads returning data from the database

When I try and go to /api/admin in order to access the admin panel I am greeted with a Not Found
However when I go to /api/api/admin it “works” (the html is loaded but the js is still trying to be loaded from /api/admin)

/api/api/admin


/api/admin

/api

/api/leads

As you can see the API is working but the admin panel seems to be confused

Server.js (host and port are 0.0.0.0 and 1337)

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  url: env('STRAPI_URL', '/api'),
  port: env.int('PORT', 1337),
  admin: {
    auth: {
      secret: env('ADMIN_JWT_SECRET', 'omitted'),
    },
  },
});

Our Docker File

FROM node:14-alpine

ENV NODE_ENV production

WORKDIR /app

COPY ["package.json", "package-lock.json*", "./"]

RUN npm install --only=production

ENV STRAPI_URL '/api'

COPY . .

RUN npm run build

EXPOSE 1337

HEALTHCHECK --interval=30s --timeout=300s --retries=5 --start-period=30s CMD curl --fail http://localhost:1337/home || exit 1

CMD ["npm", "run", "start"]

Strapi Startup Logs

Ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: strapi-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  tls:
    - hosts:
        - ourdomain.dev
      secretName: cloudflare-origin-cert
  rules:
    - host: ourdomain.dev
      http:
        paths:
          - path: /api(/|$)(.*)
            pathType: Prefix
            backend:
              service:
                name: strapi-service
                port:
                  number: 80
          - path: /()(.*)
            pathType: Prefix
            backend:
              service:
                name: nuxt-service
                port:
                  number: 80

Hey @Cpaczek
I’m having the same issue with ingress.
Were you able to deploy it this way ?

Thanks

Hello @Cpaczek @Pco, please, if you solve this, could you post your solution? Facing the same thing and I would really appreciate some insight.

Thank you in advance and regards

@Pco @javierguzman

We fixed it by switching to Caddy over Nginx.

 {
      "admin": {
        "config": {},
        "listen": "0.0.0.0:2019"
      },
      "apps": {
        "http": {
          "servers": {
            "server": {
              "@id": "server",
              "automatic_https": {
                "disable": true
              },
              "listen": [
                ":443"
              ],
              "routes": [
                {
                  "handle": [
                    {
                      "handler": "subroute",
                      "routes": [
                        {
                          "handle": [
                            {
                              "handler": "subroute",
                              "routes": [
                                {
                                  "handle": [
                                    {
                                      "handler": "rewrite",
                                      "strip_path_prefix": "/api"
                                    }
                                  ]
                                },
                                {
                                  "handle": [
                                    {
                                      "handler": "reverse_proxy",
                                      "upstreams": [
                                        {
                                          "dial": "strapi-service.namespace.svc.cluster.local:80"
                                        }
                                      ]
                                    }
                                  ]
                                }
                              ]
                            }
                          ],
                          "match": [
                            {
                              "path": [
                                "/api*"
                              ]
                            }
                          ]
                        },
                        {
                          "handle": [
                            {
                              "handler": "reverse_proxy",
                              "upstreams": [
                                {
                                  "dial": "nuxt-service.namespace.svc.cluster.local:80"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ],
                  "match": [
                    {
                      "host": [
                        "domain.com"
                      ]
                    }
                  ]
                }
              ],
              "tls_connection_policies": [
                {
                  "certificate_selection": {
                    "any_tag": [
                      "ssl-tag"
                    ]
                  },
                  "match": {
                    "sni": [
                      "domain.com"
                    ]
                  }
                }
              ]
            }
          }
        },
        "tls": {
          "certificates": {
            "@id": "certs",
            "load_files": [
              {
                "certificate": "/secret/tls/domain-com/tls.crt",
                "key": "/secret/tls/domain-com/tls.key",
                "tags": [
                  "ssl-tag"
                ]
              }
            ]
          }
        }
      }
    }

Caddy config looks something like above. We have Strapi on /api and nuxt on /. You need to make sure you update the admin panel url to have the /api. FYI this is only tested on v3 as we are moving to Payload instead of migrating to v4. I hope this helped. @Pco sorry for long response didn’t see your first @

Thanks for the quick response @Cpaczek ! it is a pity that you are using now Caddy instead of Nginx Ingress. I will try to see the differences in order to spot where the error lies.

Just one last question @Cpaczek I have just realized you redirect to strapi-service port 80. By any chance do you have an Nginx pod between your Caddy and Strapi pod? Thank you again

We don’t use Nginx anywhere in our deployment pipeline.

The way we pipe it to 80 instead of 1337 is this is what our strapi-service looks like

apiVersion: v1
kind: Service
metadata:
  name: strapi-service
spec:
  selector:
    app: strapi
    tier: backend
    track: stable
  ports:
    - protocol: TCP
      port: 80
      targetPort: 1337

Thanks @Cpaczek ! I have managed to solve the problem. At the end it was something as simple as updating the DNS which I completely forgot!! Thank you for your help and have a nice day!

Hi @javierguzman , can you explain in detail, how you resolved it Please.