<p>I have this old vanilla PHP application I'm playing with, trying to Dockerize it and then put it into a Kubernetes cluster.</p>

<p>I upgraded the app to <code>php7.3-fpm</code> and I'm trying to add <code>nginx</code> to the same image. Something like how the <code>php7.3-apache</code> is, but using <code>nginx</code> and <code>php-fpm</code>. </p>

<p>I came across <a href="https://stackoverflow.com/a/53247598/3123109">this answer</a> which offers a solution for building the image. I've changed it to fit my needs, but I'm having issues getting it to actually serve the application: </p>

<ul>
<li>It just returns <code>"502 Bad Gateway nginx/1.14.2"</code> if I navigate to <code>/admin/</code></li>
<li>It just returns <code>"Welcome to nginx!"</code> if I navigate to <code>/admin</code></li>
</ul>

<p>Seems like <code>ingress-nginx</code> and <code>nginx</code> are at least communicating. Just the <code>index.php</code> isn't being served.</p>

<p>Not quite sure where I'm going wrong.</p>

<p>Here is my configuration:</p>

<pre><code># project structure

root/
  /conf
    app.conf
    default.conf
    entrypoint.sh
    file_size.ini
  /src
    index.php
    all other.php 
  Dockerfile.dev
  Dockerfile
</code></pre>

<pre><code># ingress-nginx.yaml

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/add-base-url: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/proxy-body-size: "0"
    nginx.org/client-max-body-size: "500m"
    nginx.ingress.kubernetes.io/use-regex: "true"
  name: ingress-service-dev
  namespace: default
spec:
  rules:
    - http:
        paths:
          - path: /admin/?(.*)
            backend:
              serviceName: admin-cluster-ip-service-dev
              servicePort: 4000

</code></pre>

<pre><code># admin.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: admin-deployment-dev
spec:
  replicas: 1
  selector:
    matchLabels:
      component: admin
  template:
    metadata:
      labels:
        component: admin
    spec:
      containers:
        - name: admin
          image: testappacr.azurecr.io/test-app-admin
          ports:
            - containerPort: 4000
---
apiVersion: v1
kind: Service
metadata:
  name: admin-cluster-ip-service-dev
spec:
  type: ClusterIP
  selector:
    component: admin
  ports:
    - port: 4000
      targetPort: 4000
</code></pre>

<pre><code># Dockerfile
FROM php:7.3-fpm

# PHP_CPPFLAGS are used by the docker-php-ext-* scripts
ENV PHP_CPPFLAGS="$PHP_CPPFLAGS -std=c++11"

RUN apt-get update \
    &amp;&amp; apt-get install -y nginx \ 
    &amp;&amp; apt-get install -y libpq-dev zlib1g-dev libzip-dev \
    &amp;&amp; docker-php-ext-install pgsql zip mbstring opcache 
RUN { \
        echo 'opcache.memory_consumption=128'; \
        echo 'opcache.interned_strings_buffer=8'; \
        echo 'opcache.max_accelerated_files=4000'; \
        echo 'opcache.revalidate_freq=2'; \
        echo 'opcache.fast_shutdown=1'; \
        echo 'opcache.enable_cli=1'; \
    } &gt; /usr/local/etc/php/conf.d/php-opocache-cfg.ini

COPY . /usr/share/nginx/html
COPY ./conf/default.conf /etc/nginx/conf.d/default.conf
COPY ./conf/entrypoint.sh /etc/entrypoint.sh
# COPY --chown=www-data:www-data . /app/src

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN mv "/usr/share/nginx/html/conf/file_size.ini" "$PHP_INI_DIR/conf.d/"

WORKDIR /usr/share/nginx/html/src

EXPOSE 4000

ENTRYPOINT ["sh", "/etc/entrypoint.sh"]
</code></pre>

<pre><code># default.conf

server {
    listen 4000;
    root   /usr/share/nginx/html/src;

    include /etc/nginx/default.d/*.conf;

    index app.php index.php index.html index.htm;

    client_max_body_size 500m;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ [^/]\.php(/|$) {
      fastcgi_split_path_info ^(.+?\.php)(/.*)$;
      # Mitigate https://httpoxy.org/ vulnerabilities
      fastcgi_param HTTP_PROXY "";
      fastcgi_pass 127.0.0.1:4000;
      fastcgi_index index.php;
      include fastcgi.conf;
    }
}
</code></pre>

<p>What have I screwed up here?</p>

cjones
<p>Ok, figured it out...</p>

<p>The following I had in the <code>default.conf</code> was wrong:</p>

<pre><code>fastcgi_pass 127.0.0.1:4000;
</code></pre>

<p>It should have stayed this (which was in the answer I was copying)...</p>

<pre><code>fastcgi_pass 127.0.0.1:9000;
</code></pre>

<p>Naively didn't know that this was the default for <code>php-fpm</code>.</p>
