Nginx does not serve Angular hosted in a docker image

Viewed 98

This question has been asked a million times and we've tried nearly every solution we could find to try and resolve it.

We are serving an Angular application, hosted inside an Docker image (NGINX Alpine image) within the default location, /usr/share/nginx/html/*, via a mapping 80:7021.

On our Linux box, we hooked a container to serve a bunch of images, one of them being this Angular image.

The Angular image is build with --prod base-href="/v2/" as the final URL that should be serving the app has a /v2/ location hooked up in NGINX on the Linux machine.

Inside our default configuration for NGINX on the Linux box, we have a location /v2/ hooked up and a proxy_pass to http://localhost:7021

Also inside the NGINX on the Linux box we set the mime.types accordingly, to ensure that JS/CSS is served correct.

However, the JS/CSS files are not served. By default, if NGINX cannot find a file, it serves the standard index.html file instead, resulting in the dreaded "resource served as text/html" error.

We have tried every possible scenario to resolve this so I'm turning here in hopes that someone has seen this behavior not being resolved and can supply a resolution other than mime.types and location /.css.

Again, an reiteration of the two scenarios we have.

1.) A Docker image, based on NGINX Alpine

This image contains a --prod --base-href="/v2/" built version of our Angular application.

The application files are copied to /usr/share/nginx/html/*.

2.) Hostbox

The host box is running Ubuntu 18.04 distro and has NGINX 1.14.2 and Docker 19.03.6.

The host box has a container set up to run a set of images, including the Angular image, discussed above. The host box, in NGINX has a /location set up for the Angular application at /v2/*, meaning:

https://www.awesomewebsite/v2/{angular}, thus the reason why we built the account with a base-href of /v2/.

This is standard practice as far as we're aware and things should just work. Yet it doesn't. We've exhausted our Google searching. What can we try next?

0 Answers
Related