</code></pre></div><ul><li>For this example to work, a HTML response should be received from the FastCGI server being exposed</li><li>A HTTP request to the FastCGI server pod should be sent</li><li>The response should be generated by a php script as that is what we are demonstrating here</li></ul><p>The image we are using here <code>php:fpm-alpine</code> does not ship with a ready to use php script inside it. So we need to provide the image with a simple php-script for this example to work.</p><ul><li>Use <code>kubectl exec</code> to get into the example-app pod</li><li>You will land at the path <code>/var/www/html</code></li><li>Create a simple php script there at the path /var/www/html called index.php</li><li>Make the index.php file look like this</li></ul><divclass=highlight><pre><span></span><code><!DOCTYPE html>
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>FastCGI Test Worked!</p>'; ?>
</body>
</html>
</code></pre></div><ul><li>Save and exit from the shell in the pod</li><li>If you delete the pod, then you will have to recreate the file as this method is not persistent</li></ul><h3id=the-fastcgi-service>The FastCGI service<aclass=headerlinkhref=#the-fastcgi-servicetitle="Permanent link"> ¶</a></h3><p>The <em>Service</em> object example below matches port <code>9000</code> from the <em>Pod</em> object above.</p><divclass=highlight><pre><span></span><code><spanclass=nt>apiVersion</span><spanclass=p>:</span><spanclass=w></span><spanclass="l l-Scalar l-Scalar-Plain">v1</span>
</code></pre></div><h3id=the-configmap-object-and-the-ingress-object>The configMap object and the ingress object<aclass=headerlinkhref=#the-configmap-object-and-the-ingress-objecttitle="Permanent link"> ¶</a></h3><p>The <em>Ingress</em> and <em>ConfigMap</em> objects below demonstrate the supported <em>FastCGI</em> specific annotations.</p><divclass="admonition important"><pclass=admonition-title>Important</p><p>NGINX actually has 50 <ahref=https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#directives>FastCGI directives</a> All of the nginx directives have not been exposed in the ingress yet</p></div><h3id=the-configmap-object>The ConfigMap object<aclass=headerlinkhref=#the-configmap-objecttitle="Permanent link"> ¶</a></h3><p>This configMap object is required to set the parameters of <ahref=https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#directives>FastCGI directives</a></p><divclass="admonition attention"><pclass=admonition-title>Attention</p><ul><li>The <em>ConfigMap</em><strong>must</strong> be created before creating the ingress object</li></ul></div><ul><li>The <em>Ingress Controller</em> needs to find the configMap when the <em>Ingress</em> object with the FastCGI annotations is created</li><li>So create the configMap before the ingress</li><li>If the configMap is created after the ingress is created, then you will need to restart the <em>Ingress Controller</em> pods.</li></ul><divclass=highlight><pre><span></span><code><spanclass=nt>apiVersion</span><spanclass=p>:</span><spanclass=w></span><spanclass="l l-Scalar l-Scalar-Plain">v1</span>
</code></pre></div><h3id=the-ingress-object>The ingress object<aclass=headerlinkhref=#the-ingress-objecttitle="Permanent link"> ¶</a></h3><ul><li>Do not create the ingress shown below until you have created the configMap seen above.</li><li>You can see that this ingress matches the service <code>example-service</code>, and the port named <code>fastcgi</code> from above.</li></ul><divclass=highlight><pre><span></span><code>apiVersion: networking.k8s.io/v1
</code></pre></div><h2id=send-a-request-to-the-exposed-fastcgi-server>Send a request to the exposed FastCGI server<aclass=headerlinkhref=#send-a-request-to-the-exposed-fastcgi-servertitle="Permanent link"> ¶</a></h2><p>You will have to look at the external-ip of the ingress or you have to send the HTTP request to the ClusterIP address of the ingress-nginx controller pod.</p><divclass=highlight><pre><span></span><code>% curl 172.19.0.2 -H "Host: app.example.com" -vik
<p>FastCGI Test Worked</p></body>
</html>
</code></pre></div><h2id=fastcgi-ingress-annotations>FastCGI Ingress Annotations<aclass=headerlinkhref=#fastcgi-ingress-annotationstitle="Permanent link"> ¶</a></h2><p>To enable FastCGI, the <code>nginx.ingress.kubernetes.io/backend-protocol</code> annotation needs to be set to <code>FCGI</code>, which overrides the default <code>HTTP</code> value.</p><blockquote><p><code>nginx.ingress.kubernetes.io/backend-protocol: "FCGI"</code></p></blockquote><p><strong>This enables the <em>FastCGI</em> mode for all paths defined in the <em>Ingress</em> object</strong></p><h3id=the-nginxingresskubernetesiofastcgi-index-annotation>The <code>nginx.ingress.kubernetes.io/fastcgi-index</code> Annotation<aclass=headerlinkhref=#the-nginxingresskubernetesiofastcgi-index-annotationtitle="Permanent link"> ¶</a></h3><p>To specify an index file, the <code>fastcgi-index</code> annotation value can optionally be set. In the example below, the value is set to <code>index.php</code>. This annotation corresponds to <ahref=https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_index>the <em>NGINX</em><code>fastcgi_index</code> directive</a>.</p><blockquote><p><code>nginx.ingress.kubernetes.io/fastcgi-index: "index.php"</code></p></blockquote><h3id=the-nginxingresskubernetesiofastcgi-params-configmap-annotation>The <code>nginx.ingress.kubernetes.io/fastcgi-params-configmap</code> Annotation<aclass=headerlinkhref=#the-nginxingresskubernetesiofastcgi-params-configmap-annotationtitle="Permanent link"> ¶</a></h3><p>To specify <ahref=https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_param><em>NGINX</em><code>fastcgi_param</code> directives</a>, the <code>fastcgi-params-configmap</code> annotation is used, which in turn must lead to a <em>ConfigMap</em> object containing the <em>NGINX</em><code>fastcgi_param</code> directives as key/values.</p><blockquote><p><code>nginx.ingress.kubernetes.io/fastcgi-params-configmap: "example-configmap"</code></p></blockquote><p>And the <em>ConfigMap</em> object to specify the <code>SCRIPT_FILENAME</code> and <code>HTTP_PROXY</code><em>NGINX's</em><code>fastcgi_param</code> directives will look like the following:</p><divclass=highlight><pre><span></span><code><spanclass=nt>apiVersion</span><spanclass=p>:</span><spanclass=w></span><spanclass="l l-Scalar l-Scalar-Plain">v1</span>
</code></pre></div><p>Using the <em>namespace/</em> prefix is also supported, for example:</p><blockquote><p><code>nginx.ingress.kubernetes.io/fastcgi-params-configmap: "example-namespace/example-configmap"</code></p></blockquote></article></div></div></main><footerclass=md-footer><divclass="md-footer-meta md-typeset"><divclass="md-footer-meta__inner md-grid"><divclass=md-copyright> Made with <ahref=https://squidfunk.github.io/mkdocs-material/target=_blankrel=noopener> Material for MkDocs </a></div></div></div></footer></div><divclass=md-dialogdata-md-component=dialog><divclass="md-dialog__inner md-typeset"></div></div><scriptid=__configtype=application/json>{"base":"../..","features":["navigation.tabs","navigation.tabs.sticky","navigation.instant","navigation.sections"],"search":"../../assets/javascripts/workers/search.f886a092.min.js","translations":{"clipboard.copied":"Copied to clipboard","clipboard.copy":"Copy to clipboard","search.result.more.one":"1 more on this page","search.result.more.other":"# more on this page","search.result.none":"No matching documents","search.result.one":"1 matching document","search.result.other":"# matching documents","search.result.placeholder":"Type to start searching","search.result.term.missing":"Missing","select.version":"Select version"}}</script><scriptsrc=../../assets/javascripts/bundle.aecac24b.min.js></script></body></html>