Is it possible to set the worker_processes attribute in the nginx.conf of the staticfile_buildpack to different value from 1
search cancel

Is it possible to set the worker_processes attribute in the nginx.conf of the staticfile_buildpack to different value from 1

book

Article ID: 420907

calendar_today

Updated On:

Products

VMware Tanzu Platform - Cloud Foundry

Issue/Introduction

There is no direct way to set this up:


if you follow https://docs.cloudfoundry.org/buildpacks/staticfile/index.html#staticfile


there are certain parameters that can be configured during cf push 

Also there is a KB https://knowledge.broadcom.com/external/article/298345/erb-templating-of-the-nginxconf-file-no.html


That explains different approaches to update certain params, however  none of them is able to change the number of worker_processes


From  how-to-conf-nginx-worker-connections-with-cf-buildpack-staticfile  

"If you need to customize these settings  use the nginx-buildpack instead and just provide a full custom nginx.conf file.

You can run once using the staticfile buildpack, cf ssh into the container, copy out the generated config file for your app, then switch to the nginx-buildpack and use the copied config file. That will give you a base configuration file, you can then edit as you need and get something similar."

 

Environment

Tanzu  Elastic Application Runtime

Cause

The required parameters are defined as static and cannot be overwritten.

Resolution

Here is a working example to set number of worker_processes using nginx_buildpack:

To compile the app used: https://github.com/govau/cf-example-staticfile

Completed the following steps:

1. updated the manifest file 

 

applications:
- name: cf-example-staticfile
  random-route: true
  buildpack: nginx_buildpack  # <--- CHANGE THIS
  memory: 64M
  disk_quota: 256M
  path: .                     # <--- CHANGE THIS (Uploads everything, including config)


2. In main folder create file nginx.conf 

# nginx.conf
worker_processes 3;  # <--- Your custom setting
daemon off;

events {
    worker_connections 1024;
}

http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;

    server {
        # The NGINX Buildpack replaces {{port}} with the actual port number
        listen {{port}};
        
        # Point this to your content folder
        root web;  
        
        index index.html;
        
        location / {
            try_files $uri $uri/ =404;
        }
    }
}

3. create file mime.types in same folder

 types {
    text/html                             html htm shtml;
    text/css                              css;
    text/xml                              xml;
    image/gif                             gif;
    image/jpeg                            jpeg jpg;
    application/javascript                js;
    application/atom+xml                  atom;
    application/rss+xml                   rss;
    font/ttf                              ttf;
    font/woff                             woff;
    font/woff2                            woff2;
    text/mathml                           mml;
    text/plain                            txt;
    text/vnd.sun.j2me.app-descriptor      jad;
    text/vnd.wap.wml                      wml;
    text/x-component                      htc;
    image/png                             png;
    image/svg+xml                         svg svgz;
    image/tiff                            tif tiff;
    image/vnd.wap.wbmp                    wbmp;
    image/webp                            webp;
    image/x-icon                          ico;
    image/x-jng                           jng;
    image/x-ms-bmp                        bmp;
    application/font-woff                 woff;
    application/java-archive              jar war ear;
    application/json                      json;
    application/mac-binhex40              hqx;
    application/msword                    doc;
    application/pdf                       pdf;
    application/postscript                ps eps ai;
    application/rtf                       rtf;
    application/vnd.apple.mpegurl         m3u8;
    application/vnd.google-earth.kml+xml  kml;
    application/vnd.google-earth.kmz      kmz;
    application/vnd.ms-excel              xls;
    application/vnd.ms-fontobject         eot;
    application/vnd.ms-powerpoint         ppt;
    application/vnd.wap.wmlc              wmlc;
    application/vnd.google-earth.kml+xml  kml;
    application/vnd.google-earth.kmz      kmz;
    application/x-7z-compressed           7z;
    application/x-cocoa                   cco;
    application/x-java-archive-diff       jardiff;
    application/x-java-jnlp-file          jnlp;
    application/x-makeself                run;
    application/x-perl                    pl pm;
    application/x-pilot                   prc pdb;
    application/x-rar-compressed          rar;
    application/x-redhat-package-manager  rpm;
    application/x-sea                     sea;
    application/x-shockwave-flash         swf;
    application/x-stuffit                 sit;
    application/x-tcl                     tcl tk;
    application/x-x509-ca-cert            der pem crt;
    application/x-xpinstall               xpi;
    application/xhtml+xml                 xhtml;
    application/xspf+xml                  xspf;
    application/zip                       zip;
    application/octet-stream              bin exe dll;
    application/octet-stream              deb;
    application/octet-stream              dmg;
    application/octet-stream              iso img;
    application/octet-stream              msi msp msm;
    audio/midi                            mid midi kar;
    audio/mpeg                            mp3;
    audio/ogg                             ogg;
    audio/x-m4a                           m4a;
    audio/x-realaudio                     ra;
    video/3gpp                            3gpp 3gp;
    video/mp2t                            ts;
    video/mp4                             mp4;
    video/mpeg                            mpeg mpg;
    video/quicktime                       mov;
    video/webm                            webm;
    video/x-flv                           flv;
    video/x-m4v                           m4v;
    video/x-mng                           mng;
    video/x-ms-asf                        asx asf;
    video/x-ms-wmv                        wmv;
    video/x-msvideo                       avi;
}

Finally the folder looks like this 

drwxrwxr-x 6 ubuntu ubuntu 4096 Dec  3 17:13 ./
drwxr-x--- 7 ubuntu ubuntu 4096 Dec  3 17:05 ../
drwxrwxr-x 2 ubuntu ubuntu 4096 Dec  3 16:14 .circleci/
drwxrwxr-x 8 ubuntu ubuntu 4096 Dec  3 16:14 .git/
-rw-rw-r-- 1 ubuntu ubuntu  141 Dec  3 17:12 manifest.yml
-rw-rw-r-- 1 ubuntu ubuntu 3932 Dec  3 17:13 mime.types
-rw-rw-r-- 1 ubuntu ubuntu  516 Dec  3 17:13 nginx.conf
-rw-rw-r-- 1 ubuntu ubuntu 1727 Dec  3 16:14 README.md
drwxrwxr-x 2 ubuntu ubuntu 4096 Dec  3 16:14 scripts/
drwxrwxr-x 2 ubuntu ubuntu 4096 Dec  3 17:05 web/

Deploy the app
 

cf push


and result in the app

cf ssh cf-example-staticfile -c "cat /home/vcap/app/nginx.conf" | grep worker_processes
worker_processes 3;  # <--- Your custom setting
ubuntu@opsmanager-3-2:~$ cf ssh cf-example-staticfile
vcap@fbd642c0-ef5f-4202-7e3c-a067:~$ ps -ef
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 17:14 ?        00:00:00 /tmp/garden-init
vcap           7       0  0 17:14 ?        00:00:00 /tmp/lifecycle/diego-sshd --allowedKeyExchanges= --address=0.0.0.0:2222 --allowUnauthenticatedClients=false --inheritDaemon
root           8       0  0 17:14 ?        00:00:00 sh -c trap 'kill -9 0' TERM; /etc/cf-assets/envoy/envoy -c /etc/cf-assets/envoy_config/envoy.yaml --drain-time-s 900 --log-
vcap          19       0  0 17:14 ?        00:00:00 nginx: master process nginx -p /home/vcap/app -c ./nginx.conf
root          72       8  0 17:14 ?        00:00:00 /etc/cf-assets/envoy/envoy -c /etc/cf-assets/envoy_config/envoy.yaml --drain-time-s 900 --log-level critical
vcap          93      19  0 17:14 ?        00:00:00 nginx: worker process
vcap          94      19  0 17:14 ?        00:00:00 nginx: worker process
vcap          95      19  0 17:14 ?        00:00:00 nginx: worker process
root         110       0  0 17:14 ?        00:00:00 /etc/cf-assets/healthcheck/healthcheck -port=8080 -timeout=1000ms -liveness-interval=30s
vcap         136       7  0 17:16 pts/0    00:00:00 /bin/bash
vcap         143     136  0 17:16 pts/0    00:00:00 ps -ef

 

In case the static_buildpack is required,  create  a copy of the buildpack update the nginx.conf and rebuild it as alternative approach.