# Custom NGINX template - NGINX Ingress Controller

Skip to content

# Custom NGINX template

The NGINX template is located in the file `/etc/nginx/template/nginx.tmpl`.

Using a Volume it is possible to use a custom template. This includes using a Configmap as source of the template

            volumeMounts:
              - mountPath: /etc/nginx/template
                name: nginx-template-volume
                readOnly: true
          volumes:
            - name: nginx-template-volume
              configMap:
                name: nginx-template
                items:
                - key: nginx.tmpl
                  path: nginx.tmpl

Please note the template is tied to the Go code. Do not change names in the variable `$cfg`.

For more information about the template syntax please check the Go template package. In addition to the built-in functions provided by the Go package the following functions are also available:

- empty: returns true if the specified parameter (string) is empty
- contains: strings.Contains
- hasPrefix: strings.HasPrefix
- hasSuffix: strings.HasSuffix
- toUpper: strings.ToUpper
- toLower: strings.ToLower
- quote: wraps a string in double quotes
- buildLocation: helps to build the NGINX Location section in each server
- buildProxyPass: builds the reverse proxy configuration
- buildRateLimit: helps to build a limit zone inside a location if contains a rate limit annotation

TODO:

- buildAuthLocation:
- buildAuthResponseHeaders:
- buildResolvers:
- buildDenyVariable:
- buildUpstreamName:
- buildForwardedFor:
- buildAuthSignURL:
- buildNextUpstream:
- filterRateLimits:
- formatIP:
- getenv:
- getIngressInformation:
- serverConfig:
- isLocationAllowed:
- isValidClientBodyBufferSize: