<p>I have a strange result from using nginx and IIS server together in single Kubernetes pod. It seems to be an issue with nginx.conf. If I bypass nginx and go directly to IIS, I see the standard landing page -
<a href="https://i.stack.imgur.com/lJ1IG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lJ1IG.png" alt="enter image description here" /></a></p>
<p>However when I try to go through the reverse proxy I see this partial result -
<a href="https://i.stack.imgur.com/zA6hc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zA6hc.png" alt="enter image description here" /></a></p>
<p>Here are the files:</p>
<p>nginx.conf:</p>
<pre><code>events {
  worker_connections  4096;  ## Default: 1024
}

http{
    server {
       listen 81;
       #Using variable to prevent nginx from checking hostname at startup, which leads to a container failure / restart loop, due to nginx starting faster than IIS server. 
       set $target &quot;http://127.0.0.1:80/&quot;; 
       location / { 
          proxy_pass $target; 
       }
     }
}
</code></pre>
<p>deployment.yaml:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    ...
  name: ...
spec:
  replicas: 1
  selector:
    matchLabels:
      pod: ...
  template:
    metadata:
      labels:
        pod: ...
      name: ...
    spec:
      containers:
        - image: claudiubelu/nginx:1.15-1-windows-amd64-1809
          name: nginx-reverse-proxy
          volumeMounts:
            - mountPath: &quot;C:/usr/share/nginx/conf&quot; 
              name: nginx-conf
          imagePullPolicy: Always
        - image: some-repo/proprietary-server-including-iis
          name: ...
          imagePullPolicy: Always
      nodeSelector:
        kubernetes.io/os: windows
      imagePullSecrets:
        - name: secret1
      volumes:
        - name: nginx-conf
          persistentVolumeClaim:
            claimName: pvc-nginx
</code></pre>
<p>Mapping the nginx.conf file from a volume is just a convenient way to rapidly test different configs. New configs can be swapped in using <code>kubectl cp ./nginx/conf nginx-busybox-pod:/mnt/nginx/</code>.</p>
<p>Busybox pod (used to access the PVC):</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: nginx-busybox-pod
  namespace: default
spec:
  containers:
    - image: busybox
      command:
        - sleep
        - &quot;360000&quot;
      imagePullPolicy: Always
      name: busybox
      volumeMounts:
       - name: nginx-conf
         mountPath: &quot;/mnt/nginx/conf&quot;
  restartPolicy: Always
  volumes:
    - name: nginx-conf
      persistentVolumeClaim:
        claimName: pvc-nginx
  nodeSelector:
    kubernetes.io/os: linux
</code></pre>
<p>And lastly the PVC:</p>
<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-nginx
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 100Mi
  storageClassName: azurefile  
</code></pre>
<p>Any ideas why?</p>

jrbe228
<p>After some testing, here is a working nginx.conf -</p>
<pre><code>http{  
    server {  
       listen 81;  
       set $target &quot;http://127.0.0.1:80&quot;; 
       location / { 
          proxy_pass $target; 
          proxy_set_header Host $host;
       }
     }
}
</code></pre>
<ul>
<li>New directive - <code>proxy_set_header Host $host;</code></li>
<li>Trailing slash removed from the <code>target</code> variable used by the proxy_pass directive.</li>
<li>(Specific to my application) Other endpoints on the server are better reachable using <code>$host:$server_port</code> in place of <code>$host</code>. This is caused by the app server redirecting incoming requests to different URIs, losing the proxy's port (81) in the process.</li>
</ul>
