I am using Ingress NGINX in my Kubernetes cluster: https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/
Since Ingress NGINX supports Fast CGI as direct backend, I run a container with a Laravel app serving through php-fpm on port 9000. Now I tried to use Ingress NGINX as proxy with FCGI as backend, but I am not able to configure it.
According to the Laravel documentation, a nginx configuration should look like this (https://laravel.com/docs/8.x/deployment):
server {
listen 80;
server_name example.com;
root /srv/example.com/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
Unfortunately, it looks like not able to create the locations for /
and for ~ \.php$
since Ingress NGINX does reserve the location /
without any reason.
My configuration looks like this:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: ingress-fastcgi
namespace: default
annotations:
kubernetes.io/ingress.class: "nginx"
kubernetes.io/ingress.allow-http: "false"
cert-manager.io/cluster-issuer: "letsencrypt-production"
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
nginx.ingress.kubernetes.io/backend-protocol: "FCGI"
nginx.ingress.kubernetes.io/fastcgi-index: "index.php"
spec:
tls:
- hosts:
- api.abcxyz.cloud
secretName: api-cert-secret
rules:
- host: api.abcxyz.cloud
http:
paths:
- path: /
backend:
serviceName: laravel
servicePort: 9000
How can I handle the requirements coming from Laravel with Ingress NGINX and FCGI?