<p>I have Kubernetes set up in a home lab and I am able to get a vanilla implementation of nginx running from a deployment.</p>
<p>The next step is to have a custom nginx.conf file for the configuration of nginx.  For this, I am using a ConfigMap.</p>
<p>When I do this, I no longer receive the nginx index page when I navigate to <a href="http://192.168.1.10:30008" rel="noreferrer">http://192.168.1.10:30008</a> (my local ip address for the node the nginx server is running on).  If I try to use the ConfigMap, I receive the nginx 404 page/message.</p>
<p>I am not able to see what I am doing incorrectly here.  Any direction would be much appreciated.</p>
<p>nginx-deploy.yaml</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-conf
data:
  nginx.conf: |
    user nginx;
    worker_processes  1;
    events {
      worker_connections  10240;
    }
    http {
      server {
          listen       80;
          server_name  localhost;
          location / {
            root   html;
            index  index.html index.htm;
        }
      }
    }

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        volumeMounts:
            - name: nginx-conf
              mountPath: /etc/nginx/nginx.conf
              subPath: nginx.conf
              readOnly: true
      volumes:
      - name: nginx-conf
        configMap:
          name: nginx-conf
          items:
            - key: nginx.conf
              path: nginx.conf

---
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  type: NodePort
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
    nodePort: 30008
  selector:
    app: nginx 
</code></pre>

Eric
<p>Nothing complex, it's the root directory in the <code>nginx.conf</code> is not defined correctly.</p>
<p>Checking the logs with <code>kubectl logs &lt;&lt;podname&gt;&gt; -n &lt;&lt;namespace&gt;&gt;</code> gives why the <code>404 error</code> is happening for a particular request.</p>
<p><code>xxx.xxx.xxx.xxx - - [02/Oct/2020:22:26:57 +0000] &quot;GET / HTTP/1.1&quot; 404 153 &quot;-&quot; &quot;curl/7.58.0&quot; 2020/10/02 22:26:57 [error] 28#28: *1 &quot;/etc/nginx/html/index.html&quot; is not found (2: No such file or directory), client: xxx.xxx.xxx.xxx, server: localhost, request: &quot;GET / HTTP/1.1&quot;, host: &quot;xxx.xxx.xxx.xxx&quot;</code></p>
<p>It's because of <code>location</code> inside your <code>configmap</code> is referring to wrong directory as root <code>root html</code>.</p>
<p>Change the location to a directory which has <code>index.html</code> will fix the issue. Here is the working configmap with <code>root   /usr/share/nginx/html</code>. However this could be manipulated as you want, but we need to make sure files exist in the directory.</p>
<pre><code>
apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-conf
data:
  nginx.conf: |
    user nginx;
    worker_processes  1;
    events {
      worker_connections  10240;
    }
    http {
      server {
          listen       80;
          server_name  localhost;
          location / {
            root   /usr/share/nginx/html; #Change this line
            index  index.html index.htm;
        }
      }
    }

</code></pre>
