I am hosting a web application inside a Kubernetes 1.13 cluster behind an NGINX ingress controller. The Ingress
specifies path: /my-webapp/?(.*)
and annotations:
{ nginx.ingress.kubernetes.io/rewrite-target: /$1 }
such that the webapp can be reached from outside the cluster at http://my-cluster/my-webapp
. (The ingress controller is exposed as my-cluster
.)
One remaining problem is that the webapp contains "relative" URLs that refer e.g. to CGI scripts and to CSS stylesheets. For instance, the stylesheet in <link rel="stylesheet" type="text/css" href="/my-stylesheet.css" />
currently does not load. I assume this is because the browser requests it at the wrong URL (http://my-cluster/my-webapp/my-stylesheet.css
would be right) and that some more annotations are needed.
What is the correct configuration is such a case?
UPDATE The inspector reveals that the browser currently requests the stylesheet from URL http://my-cluster/my-stylesheet.css
, which is indeed wrong and needs to be fixed.
UPDATE This looks like a related problem with an NGINX reverse proxy in general, not a Kubernetes NGINX ingress controller in particular. I wonder if and how the suggested recipes can also serve in this particular case. For a start, I have tried switching to a relative URL for referencing the stylesheet (per recipe One in the accepted answer), but this also has not worked so far:
<link rel="stylesheet" type="text/css" href="my-stylesheet.css" />
, the browser apparently still tries to get the stylesheet from http://my-cluster/my-stylesheet.css
, although it displays http://my-cluster/my-webapp
in the URL bar and the inspector reports the same URL as baseURI
.