<p>I am trying to deploy an angular based webapp to kube, I am trying to deploy it as static content using nginx.<br />
The problem is the URL's are not accessible; meaning if I try to access <a href="https://website.company.com/route1" rel="nofollow noreferrer">https://website.company.com/route1</a>, I get a <code>404 not found</code> error, I can access <a href="https://website.company.com" rel="nofollow noreferrer">https://website.company.com</a> and then click on <code>route1</code> from homepage it takes me to <a href="https://website.company.com/route1" rel="nofollow noreferrer">https://website.company.com/route1</a></p>
<p>Any guidance on what am I missing here?</p>
<p>Following are my <em>Dockerfile</em> and <em>nginx.conf.erb</em></p>
<p><em>Dockerfile</em>:</p>
<pre class="lang-sh prettyprint-override"><code>FROM nginx
EXPOSE 80
COPY www/* /usr/share/nginx/html
COPY nginx.conf.erb /etc/nginx/nginx.conf.erb
</code></pre>
<p><em>nginx.conf.erb</em>:</p>
<pre class="lang-conf prettyprint-override"><code>worker_processes 1;
error_log stderr;
pid /app/.nginx-tmp/pid;
daemon off;

events {
        worker_connections 768;
}

http {
        include mime.types;
        client_body_temp_path /app/.nginx-tmp/body    1 2;
        proxy_temp_path       /app/.nginx-tmp/cache   1 2;
        fastcgi_temp_path     /app/.nginx-tmp/fastcgi 1 2;
        uwsgi_temp_path       /app/.nginx-tmp/uwsgi   1 2;
        scgi_temp_path        /app/.nginx-tmp/scgi    1 2;
        access_log off;
        server {
                listen &lt;%= ENV['PORT'] %&gt;;
                server_name _;
                root /app/www;
                index index.html;
                location = /__health {
                        return 200 'OK';
                        add_header Content-Type text/plain;
                }

                location / {
                        try_files $uri $uri/ /index.html;
                }
        }
}
</code></pre>
<p><strong>UPDATE:</strong></p>
<p><em>Dockerfile:</em></p>
<pre class="lang-sh prettyprint-override"><code>FROM nginx
RUN mkdir -p /app/.nginx-tmp
COPY www/* /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
</code></pre>
<p><em>nginx.conf</em></p>
<pre><code>worker_processes 1;
error_log stderr;
pid /app/.nginx-tmp/pid;
events {
        worker_connections 768;
}
http {
        include mime.types;
        client_body_temp_path /app/.nginx-tmp/body    1 2;
        proxy_temp_path       /app/.nginx-tmp/cache   1 2;
        fastcgi_temp_path     /app/.nginx-tmp/fastcgi 1 2;
        uwsgi_temp_path       /app/.nginx-tmp/uwsgi   1 2;
        scgi_temp_path        /app/.nginx-tmp/scgi    1 2;
        access_log off;
        server {
                listen 80;
                server_name _;
                root /app/www;
                index index.html;
                location = /__health {
                        return 200 'OK';
                        add_header Content-Type text/plain;
                }
                location / {
                        try_files $uri $uri/ /index.html;
                }
        }
}
</code></pre>
<p>Error:</p>
<blockquote>
<pre class="lang-none prettyprint-override"><code>2020/12/18 01:43:53 [error] 31#31: *2 rewrite or internal redirection cycle while internally redirecting to &quot;/index.html&quot;, client: 172.17.0.1, server: _, request: &quot;GET / HTTP/1.1&quot;, host: &quot;localhost:8080&quot;
2020/12/18 01:43:53 [error] 31#31: *1 rewrite or internal redirection cycle while internally redirecting to &quot;/index.html&quot;, client: 172.17.0.1, server: _, request: &quot;GET /favicon.ico HTTP/1.1&quot;, host: &quot;localhost:8080&quot;, referrer: &quot;http://localhost:8080/&quot;
</code></pre>
</blockquote>

<p>Indeed, NGINX is not going to understand a <code>nginx.conf.erb</code> file.<br />
It looks like <a href="https://stackoverflow.com/questions/tagged/passenger"><kbd>Passenger</kbd></a> would allow this type of file type but the &quot;vanilla&quot; <a href="https://hub.docker.com/_/nginx" rel="nofollow noreferrer">NGINX image</a> won't.</p>
<p>So you will want your file to be a simple <code>.conf</code> file and to be copied over the existing <em>/etc/nginx/nginx.conf</em> file.</p>
<pre class="lang-sh prettyprint-override"><code>FROM nginx
EXPOSE 80
COPY www/* /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf 
## off course, you'll have to rename your host file to nginx.conf too.
</code></pre>
<p>Note that for this, you will also have to fix this line in the configuration file:</p>
<pre class="lang-none prettyprint-override"><code>listen &lt;%= ENV['PORT'] %&gt;;
</code></pre>
<p>Because this a ruby erb syntax and it won't be accepted nor interpreted by NGINX.</p>
<p>And, because your <code>containerPort</code> is explicitly specifying that it exposes the port <code>3000</code> of the container, I would expect you will be safe with:</p>
<pre class="lang-none prettyprint-override"><code>listen 3000;
</code></pre>
<p>But if this is not the case, you can use the solution prompted in the docker image documentation</p>
<blockquote>
<p>Out-of-the-box, nginx doesn't support environment variables inside most configuration blocks. But this image has a function, which will extract environment variables before nginx starts.</p>
<p>Here is an example using docker-compose.yml:</p>
<pre class="lang-yaml prettyprint-override"><code>web:
  image: nginx
  volumes:
   - ./templates:/etc/nginx/templates
  ports:
   - &quot;8080:80&quot;
  environment:
   - NGINX_HOST=foobar.com
   - NGINX_PORT=80
</code></pre>
<p>By default, this function reads template files in <code>/etc/nginx/templates/*.template</code> and outputs the result of executing <code>envsubst</code> to <code>/etc/nginx/conf.d</code>.</p>
<p>So if you place <code>templates/default.conf.template</code> file, which contains variable references like this:</p>
<pre class="lang-none prettyprint-override"><code>listen       ${NGINX_PORT};
</code></pre>
<p>outputs to <code>/etc/nginx/conf.d/default.conf</code> like this:</p>
<pre class="lang-none prettyprint-override"><code>listen       80;
</code></pre>
</blockquote>
<p><sup><em>Source: <a href="https://hub.docker.com/_/nginx" rel="nofollow noreferrer">https://hub.docker.com/_/nginx</a></em></sup></p>
