<p>First a little background:</p>
<p>We currently have several websites and services hosted on a Plesk server and I am setting up a bare-metal development server to provide an area where we can test updates, etc. before going to production.  I am using a 3 node kubernetes cluster running microk8s on Ubunutu 20.04.01.  The services we host are pretty diverse:  we have a couple Moodle sites, a few Wordpress sites, a site running limesurvery, an instance of Mantis bugtracker, and a few more.  I have successfully gotten most of the sites containerized and running on k8s.  I can also access each individual site either through a NodePort or a MetalLB load balancer.</p>
<p>However, I'd really like to use the NGINX Ingress Controller on top of the load balancer so that I can have a consistent way to access the sites without using a bunch of IP addresses (or in the NodePort case, ports that change).  No matter what I've done, I cannot seem to get the Ingress to do what I want.  I simply want to do the following:
<code>http://&lt;LB IP Address&gt;/bugtracker</code> to access the Mantis Bug Tracker site
<code>http://&lt;LB IP Address&gt;/moodle1</code> to access one of the Moodle sites
<code>http://&lt;LB IP Address&gt;/limesurvey</code> to access the limesurvey,
etc.  I seem to be able to get to the main page of the site (e.g. index.html, index.php, etc.), but any references from there on do not work - i.e. they give path not found errors or 404 errors.</p>
<p>Here's a sample of my Ingress file:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
  - http:
      paths:
      - path: /limesurvey(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: limesurvey-svc
            port:
              number: 80
      - path: /moodle(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: moodle-svc
            port:
              number: 8080
</code></pre>
<p>This ingress does not work (I get the 404s).  However, if I only have one path in the file and just use '/' it works (but I can only use it for one service):</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: limesurvey-svc
            port:
              number: 80
</code></pre>
<p>I think what I need is for the path (limesurvey) to continue to be pre-pended onto each URL request, but I cannot seem to make this happen.  The reason I think this is because when I navigate to <code>http://&lt;LB IP Address&gt;/limesurvey</code> and click on a survey, I get a 404 error at <code>http://&lt;LB IP Address&gt;/index.php/&lt;survey number&gt;</code>.  However, if I manually change the URL in my browser to <code>http://&lt;LB IP Address&gt;/limesurvey/index.php/&lt;survey number&gt;</code> it will access the survey (but still have 404s with supporting assets).</p>
<p>Am I trying to do something outside of what the Ingress controller was designed for?  I feel like I should be able to use the rewrite-target to accomplish this but I'm missing something critical.</p>
<p>I appreciate any help.</p>

Ben Hartman
<p>Some applications relay on <code>static content</code> served from different <code>URL webserver</code> locations and moreover do internal <code>path routing</code> (e.g. you hit <code>&quot;/&quot;</code> path but get served <code>&quot;/admin&quot;</code> section immediately).</p>
<p>In such cases creation of right <code>Ingress</code> rules gets more tricky, and requires you to better understand behavior and constructs of your web application, to predict all possible URL path locations that user may visit (these forced by app internal redirects too), and these sourced by <code>html</code> code as well.</p>
<p>Seems like your case with <code>limesurvey</code> app falls into that category:</p>
<p><em>Why do I think that?</em> <br>
Just try to open limesurvey public demo (<a href="https://demo.limesurvey.org/" rel="nofollow noreferrer">https://demo.limesurvey.org/</a>) and inspect site content.</p>
<p>You will learn that main page is using a lot of static files (e.g. <code>css</code>, <code>javascrpt files</code>), referenced from absolute path starting with: <code>/tmp/assets/...</code></p>
<pre><code>&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/tmp/assets/2d523ae6/survey.css&quot; /&gt;
</code></pre>
<p>of course variants of different path locations can be matched with single smart <code>reg-ex</code> pattern, to avoid creation of dozen of individual ingress rules (what you tried).</p>
<p><em>What's the issue?</em></p>
<pre><code>rules:
  - http:
      paths:
      - path: /limesurvey(/|$)(.*) &lt;---- it won't match &quot;/tmp/assets/...&quot; location
        pathType: Prefix
        backend:
          service:
            name: limesurvey-svc
            port:
              number: 80
</code></pre>
<p>Please try to create additional <code>Ingress</code> rule to support static file location (watch out, I'm using old syntax of Ingress resource, adjust it to your needs):</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
  name: ingress-limesurvey-static
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: limesurvey-svc
          servicePort: 80
        path: /?(.*)
</code></pre>
<h2>Best Solution (in my opinion)</h2>
<p>You should define custom public URL within your application directly. Detailed information can be found in <a href="https://manual.limesurvey.org/Optional_settings#Advanced_path_settings" rel="nofollow noreferrer">Advanced path settings</a>, see <code>publicurl</code> option.</p>
<p>This way you wouldn't need to define internal reference for static files, however it should be done during installation.</p>
