I have this old vanilla PHP application I'm playing with, trying to Dockerize it and then put it into a Kubernetes cluster.
I upgraded the app to php7.3-fpm
and I'm trying to add nginx
to the same image. Something like how the php7.3-apache
is, but using nginx
and php-fpm
.
I came across this answer 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:
"502 Bad Gateway nginx/1.14.2"
if I navigate to /admin/
"Welcome to nginx!"
if I navigate to /admin
Seems like ingress-nginx
and nginx
are at least communicating. Just the index.php
isn't being served.
Not quite sure where I'm going wrong.
Here is my configuration:
# project structure
root/
/conf
app.conf
default.conf
entrypoint.sh
file_size.ini
/src
index.php
all other.php
Dockerfile.dev
Dockerfile
# 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
# 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
# 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 \
&& apt-get install -y nginx \
&& apt-get install -y libpq-dev zlib1g-dev libzip-dev \
&& 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'; \
} > /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"]
# 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;
}
}
What have I screwed up here?
Ok, figured it out...
The following I had in the default.conf
was wrong:
fastcgi_pass 127.0.0.1:4000;
It should have stayed this (which was in the answer I was copying)...
fastcgi_pass 127.0.0.1:9000;
Naively didn't know that this was the default for php-fpm
.