<p>I am using Ingress NGINX in my Kubernetes cluster: <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/</a></p>
<p>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.</p>
<p>According to the Laravel documentation, a nginx configuration should look like this (<a href="https://laravel.com/docs/8.x/deployment" rel="nofollow noreferrer">https://laravel.com/docs/8.x/deployment</a>):</p>
<pre><code>server {
    listen 80;
    server_name example.com;
    root /srv/example.com/public;

    add_header X-Frame-Options &quot;SAMEORIGIN&quot;;
    add_header X-XSS-Protection &quot;1; mode=block&quot;;
    add_header X-Content-Type-Options &quot;nosniff&quot;;

    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;
    }
}
</code></pre>
<p>Unfortunately, it looks like not able to create the locations for <code>/</code> and for <code>~ \.php$</code> since Ingress NGINX does reserve the location <code>/</code> without any reason.</p>
<p>My configuration looks like this:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ingress-fastcgi
  namespace: default
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
    kubernetes.io/ingress.allow-http: &quot;false&quot;
    cert-manager.io/cluster-issuer: &quot;letsencrypt-production&quot;
    nginx.ingress.kubernetes.io/force-ssl-redirect: &quot;true&quot;
    nginx.ingress.kubernetes.io/backend-protocol: &quot;FCGI&quot;
    nginx.ingress.kubernetes.io/fastcgi-index: &quot;index.php&quot;
spec:
  tls:
    - hosts:
        - api.abcxyz.cloud
      secretName: api-cert-secret
  rules:
    - host: api.abcxyz.cloud
      http:
        paths:
          - path: /
            backend:
              serviceName: laravel
              servicePort: 9000

</code></pre>
<p>How can I handle the requirements coming from Laravel with Ingress NGINX and FCGI?</p>

floflock
<p>I think the listening port of your nginx configuration should be 9000.</p>
<p>My guess, what you have is:</p>
<ul>
<li>a container with PHP app served by Nginx at port 9000.</li>
<li>a ClusterIP service at service port 80, mapped to you port 9000 container port.</li>
<li>then you are trying expose your service to outside world using ingress</li>
</ul>
<p>So you need the following k8 declarations</p>
<ul>
<li>Deployment/Statefulset - to create your container.</li>
<li>Service - to map your service port 80 to container port 9000</li>
<li>Ingress - to expose your service to outside work at port 80</li>
</ul>
<p>here is an example (although I use <code>ambassador</code> ingress.class for minikube but the principle is the same) <a href="https://github.com/francisfueconcillo/k8-geektalk/blob/master/wp-deployment.yaml" rel="nofollow noreferrer">https://github.com/francisfueconcillo/k8-geektalk/blob/master/wp-deployment.yaml</a></p>
