<p>How do i need to configure my ingress that Angular 7 App is working?</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: myingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/use-regex: "true"
spec:
  rules:
  - http:
      paths:
      - path:
        backend:
          serviceName: angular-service
          servicePort: 80
      - path: /test
        backend:
          serviceName: angular-service
          servicePort: 80
</code></pre>

<p>Angular is hosted by nginx image:</p>

<pre><code>FROM nginx:alpine
COPY . /usr/share/nginx/html
</code></pre>

<p>And on Kubernetes:</p>

<p>kind: Service
apiVersion: v1
metadata:
  name: test-service
spec:
  selector:
    app: test
  ports:</p>

<h2>    - port: 80</h2>

<p>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: test
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": linux
      containers:
      - name: test
        image: xxx.azurecr.io/test:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 80</p>

<p>On path / everything works. But on /test it doesn't work.
Output in console:</p>

<blockquote>
  <p>Uncaught SyntaxError: Unexpected token &lt; runtime.js:1 </p>
  
  <p>Uncaught SyntaxError: Unexpected token &lt; polyfills.js:1</p>
  
  <p>Uncaught SyntaxError: Unexpected token &lt; main.js:1</p>
</blockquote>

<p>That´s why I changed on angular.json:</p>

<pre><code>"baseHref" : "/test",
</code></pre>

<p>But now I get the same error on both locations. What I´m doing wrong?</p>

<h2>edit details</h2>

<h3>ingress-controller (Version 0.25.0):</h3>

<p><a href="https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml" rel="nofollow noreferrer">https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml</a></p>

<h3>ingress-service (for azure):</h3>

<p><a href="https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud-generic.yaml" rel="nofollow noreferrer">https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud-generic.yaml</a></p>

<h3>Test Procedure:</h3>

<p>The Application is built with </p>

<pre><code>"baseHref" : "",
</code></pre>

<p>When I run the application on my server everything works (by that baseHref is verified, too).</p>

<pre><code>$ sudo docker run --name test -p 80:80 test:v1
</code></pre>

<p>On Kubernetes the application works on location / (only if I use annotation nginx.ingress.kubernetes.io/rewrite-target: /).
If I try to enter /test I get an empty page.</p>

<h3>Logs:</h3>

<p>$ sudo kubectl logs app-589ff89cfb-9plfs</p>

<pre><code>10.xxx.x.xx - - [11/Jul/2019:18:16:13 +0000] "GET / HTTP/1.1" 200 574 "https://52.xxx.xx.xx/test" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" "93.xxx.xxx.xxx"
</code></pre>

<p>$ sudo kubectl logs -n ingress-nginx nginx-ingress-controller-6df4d8b446-6rq65</p>

<p>Location /</p>

<pre><code>93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:55:31 +0000] "GET / HTTP/2.0" 200 279 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 261 0.002 [default-app2-service-80] [] 10.xxx.x.48:80 574 0.004 200 95abb8e14b1dd95976cd44f23a2d829a
93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:55:31 +0000] "GET /runtime.js HTTP/2.0" 200 2565 "https://52.xxx.xx.xx/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 44 0.001 [default-app2-service-80] [] 10.xxx.x.49:80 9088 0.004 200 d0c2396f6955e82824b1dec60d43b4ef
93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:55:31 +0000] "GET /polyfills.js HTTP/2.0" 200 49116 "https://52.xxx.xx.xx/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 25 0.000 [default-app2-service-80] [] 10.xxx.x.48:80 242129 0.000 200 96b5d57f9baf00932818f850abdfecca
93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:55:31 +0000] "GET /styles.js HTTP/2.0" 200 5464 "https://52.xxx.xx.xx/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 23 0.009 [default-app2-service-80] [] 10.xxx.x.49:80 16955 0.008 200 c3a7f1f937227a04c9eec9e1eab107b3
93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:55:31 +0000] "GET /main.js HTTP/2.0" 200 3193 "https://52.xxx.xx.xx/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 21 0.019 [default-app2-service-80] [] 10.xxx.x.49:80 12440 0.016 200 c0e12c3eaec99212444cf916c7d6b27b
93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:55:31 +0000] "GET /runtime.js.map HTTP/2.0" 200 9220 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 24 0.004 [default-app2-service-80] [] 10.xxx.x.48:80 9220 0.008 200 f1a820a384ee9e7a61c74ebb8f3cbf68
93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:55:31 +0000] "GET /vendor.js HTTP/2.0" 200 643193 "https://52.xxx.xx.xx/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 23 0.130 [default-app2-service-80] [] 10.xxx.x.48:80 3391734 0.132 200 1cf47ed0d8a0e470a131dddb22e8fc48
93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:55:31 +0000] "GET /polyfills.js.map HTTP/2.0" 200 241031 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 26 0.001 [default-app2-service-80] [] 10.xxx.x.49:80 241031 0.000 200 75413e809cd9739dc0b9b300826dd107
93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:55:31 +0000] "GET /styles.js.map HTTP/2.0" 200 19626 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 23 0.000 [default-app2-service-80] [] 10.xxx.x.48:80 19626 0.004 200 1aa0865cbf07ffb1753d0a3eb630b4d7
93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:55:32 +0000] "GET /favicon.ico HTTP/2.0" 200 1471 "https://52.xxx.xx.xx/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 55 0.048 [default-app2-service-80] [] 10.xxx.x.49:80 5430 0.000 200 2c015813c697c61f3cc6f67bb3bf7f75
93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:55:32 +0000] "GET /vendor.js.map HTTP/2.0" 200 3493937 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 24 0.377 [default-app2-service-80] [] 10.xxx.x.49:80 3493937 0.380 200 7b41bbbecafc2fb037c934b5509de245
93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:55:32 +0000] "GET /main.js.map HTTP/2.0" 200 6410 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 22 0.169 [default-app2-service-80] [] 10.xxx.x.48:80 6410 0.104 200 cc23aa543c19ddc0f55b4a922cc05d04
</code></pre>

<p>Location /test</p>

<pre><code>93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:43:08 +0000] "GET /test/ HTTP/2.0" 200 274 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 294 0.000 [default-test-service-80] [] 10.xxx.x.xx:80 574 0.000 200 2b560857eba8dd1242e359d5eea0a84b
93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:43:08 +0000] "GET /test/runtime.js HTTP/2.0" 200 274 "https://52.xxx.xx.xx/test/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 53 0.000 [default-test-service-80] [] 10.xxx.x.49:80 574 0.000 200 2695a85077c64d40a5806fb53e2977e5
93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:43:08 +0000] "GET /test/polyfills.js HTTP/2.0" 200 274 "https://52.xxx.xx.xx/test/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 30 0.003 [default-test-service-80] [] 10.xxx.x.48:80 574 0.000 200 8bd4e421ee8f7f9db6b002ac40bf2025
93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:43:08 +0000] "GET /test/styles.js HTTP/2.0" 200 274 "https://52.xxx.xx.xx/test/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 28 0.001 [default-test-service-80] [] 10.xxx.x.49:80 574 0.000 200 db7f0cb93b90a41d623552694e5e74b6
93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:43:08 +0000] "GET /test/vendor.js HTTP/2.0" 200 274 "https://52.xxx.xx.xx/test/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 28 0.001 [default-test-service-80] [] 10.xxx.x.48:80 574 0.000 200 0e5eb8fc77a6fb94b87e64384ac083e0
93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:43:08 +0000] "GET /test/main.js HTTP/2.0" 200 274 "https://52.xxx.xx.xx/test/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 27 0.001 [default-test-service-80] [] 10.xxx.x.49:80 574 0.000 200 408aa3cbfda25f65cb607e1b1ce47566
93.xxx.xxx.xxx - [93.xxx.xxx.xxx] - - [12/Jul/2019:06:43:08 +0000] "GET /test/favicon.ico HTTP/2.0" 200 274 "https://52.xxx.xx.xx/test/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" 58 0.001 [default-test-service-80] [] 10.xxx.x.48:80 574 0.000 200 d491507ae073de55a480909b4fab0484
</code></pre>

<p>Without knowing the version of nginx-ingress this is just a guess.</p>

<p>Per the documentation at <a href="https://kubernetes.github.io/ingress-nginx/examples/rewrite/#rewrite-target" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/examples/rewrite/#rewrite-target</a> is says:</p>

<blockquote>
  <p>Starting in Version 0.22.0, ingress definitions using the annotation nginx.ingress.kubernetes.io/rewrite-target are not backwards compatible with previous versions. In Version 0.22.0 and beyond, any substrings within the request URI that need to be passed to the rewritten path must explicitly be defined in a capture group.</p>
</blockquote>

<p>This means that you need to explicitly pass the paths like:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: myingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/use-regex: "true"
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: angular-service
          servicePort: 80
      - path: /test/(/|$)(.*)
        backend:
          serviceName: angular-service
          servicePort: 80
</code></pre>
