Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nginx path is ignored? Bug or wrong configuration? #735

Open
goors opened this issue Jun 28, 2022 · 2 comments
Open

Nginx path is ignored? Bug or wrong configuration? #735

goors opened this issue Jun 28, 2022 · 2 comments

Comments

@goors
Copy link

goors commented Jun 28, 2022

I have Kubernetes with ingress config:

path: /nuget(/|$)(.*)

I thought that using PathBase as env variable with resolve issue, but it is not.

In this case I thought setting PathBase=/nuget with resolve this but when I got to mydomain.com/nuget/v3/index.json
In response JSON, I have mydomain.com/api/v2/package in instead of mydomain.com/nuget/api/v2/package.

What am I missing here?

@Rayvor
Copy link

Rayvor commented Nov 12, 2022

I think you have a config like this

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-test
  annotations:
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
   - host: test.domain.com
     http:
       paths:
       - path: /nuget(/|$)(.*)  # test.domain.com/nuget/api/v3 would redirect to the baget-service:80/api/v3
         pathType: Prefix
         backend:
           service:
             name: baget-service
             port:
               number: 80

you should change to something like this

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-test
  annotations:
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$1/$3
spec:
  rules:
   - host: test.domain.com
     http:
       paths:
       - path: /(nuget)(/|$)(.*)  # test.domain.com/nuget/api/v3 would redirect to the baget-service:80/nuget/api/v3
         pathType: Prefix
         backend:
           service:
             name: baget-service
             port:
               number: 80

@Dunge
Copy link

Dunge commented Feb 3, 2023

This works for the requests coming from the external to the internal of the service, but not for the website. Like every websites hosted on in subpath, the html points to resources directly on / and doesn't work since this is another application.

Loading failed for the <script> with source “https://mydomain.com/static/js/2.efb0bbbd.chunk.js”. [nuget:1:1](https://mydomain.com/nuget)
Loading failed for the <script> with source “https://mydomain.com/static/js/main.1a468764.chunk.js”.

Is using different subdomains the only solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants