Nginx routing ignores anything after path rule

11/13/2019

We are setting up nginx with kubernetes for formio. We need the .com/ to point to the api server, and the .com/files/ to point to the pdf server. Here is the ingress config:

  paths:
  - backend:
      serviceName: formio
      servicePort: 80
    path: /
  - backend:
      serviceName: formio-files
      servicePort: 4005
    path: /files/(.*)$

We have it setup that our PDFs are being stored in the path like /files/pdf/filename. The issue is that whole path after /files/ also gets redirected to the PDF server, instead of just stopping at /files/

-- Alex
azure
kubernetes
kubernetes-ingress
nginx
nginx-ingress

2 Answers

12/17/2019

The issue is we were using the azure cloud shell with bash to apply it. Would look like this: 'kubectl apply -f ' Bash was treating the $1 as a variable instead of writing it to the config, so rewrite-target would not work. Saved the config as a YAML and applied that which fixed the problem.

Thanks for the help everyone

-- Alex
Source: StackOverflow

11/14/2019

This is a common issue and it was caused by the path regex which you set. First, you need to understand clearly about it. The path regex /files/(.*)$ will match all the path /files/..., no matter what you add after /files/. So it redirects all the requests with path /files/.... If you only want to redirect the PDF requests to the path /files/pdf/..., the solution is set the path regex as /files/pdf/(.*)$.

-- Charles Xu
Source: StackOverflow