cloudfoundry / cloudfoundry/nginx-buildpack

Running nginx as part of cf node app as multiprocess

Open
#240 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
30
Forks
68
PR merge metrics
No merged PRs in 30d

Description

What version of Cloud Foundry and CF CLI are you using? (i.e. What is the output of running cf curl /v2/info && cf version?
cf api version 2.209.0
cf cli - cf version 7.5.0+0ad1d63.2022-06-04

What version of the buildpack you are using?
nginx_buildpack-cached-cflinuxfs4-v1.2.6.zip

If you were attempting to accomplish a task, what was it you were attempting to do?
We are trying run an application with multiple process, one being nginx and other one node-js. The nginx will have rate limiiting configuration and it routes to the nodejs process. (We dont want to use the cf route service).
Manifest configuration:

---
applications:
- name: cf-nodejs
  memory: 1G
  processes:
  - type: web
    command: nginx -p /home/vcap/app -c ./nginx.conf
    instances: 1
  - type: worker
    command: node server.js
    instances: 2
  random-route: true
  buildpacks: 
   - nginx_buildpack
   - nodejs_buildpack

nginx configuration:

worker_processes 1;
daemon off;

error_log stderr;
events { worker_connections 1024; }

http {
  charset utf-8;
  log_format cloudfoundry 'NginxLog "$request" $status $body_bytes_sent';
  resolver {{nameservers}};
  access_log /dev/stdout cloudfoundry;
  default_type application/octet-stream;
  sendfile on;

  tcp_nopush on;
  keepalive_timeout 30;
  port_in_redirect off; # Ensure that redirects don't include the internal container PORT - 8080


  limit_req_zone global zone=global_limit:128m rate=1r/s;

  server {
    listen {{port}};
  
    # configuration endpoint
    location / {
      default_type application/json;
      limit_req zone=global_limit burst=3; # rule of thumb: burst = rate * 3
      limit_req_status 429;
      proxy_pass https://localhost:4000;

    }
  }
}

What did you expect to happen?
Both the process should work.

What was the actual behavior?
Nodejs process was started and running, nginx process crashed with the error

   2023-09-26T17:02:07.08+0530 [APP/PROC/WEB/0] ERR 2023/09/26 11:32:07 [emerg] 8#0: directive "resolver" is not terminated by ";" in /home/vcap/app/./nginx.conf:10

cf app output:

➜  cf-sample-app-nodejs git:(master) ✗ cf app cf-nodejs
Showing health and status for app cf-nodejs in org ORG / space SPACE as xxxx@yyy.com

name:              cf-nodejs
requested state:   started
routes:            cf-nodejs-appreciative-zebra-bd.<domain>.com
last uploaded:     Tue 26 Sep 16:51:19 IST 2023
stack:             cflinuxfs4
buildpacks:
	name               version   detect output   buildpack name
	nginx_buildpack    1.2.6                     nginx
	nodejs_buildpack   1.8.13    nodejs          nodejs

type:           web
sidecars:
instances:      0/1
memory usage:   1024M
     state     since                  cpu    memory    disk      details
#0   crashed   2023-09-26T11:32:14Z   0.0%   0 of 1G   0 of 1G

type:           worker
sidecars:
instances:      2/2
memory usage:   1024M
     state     since                  cpu    memory        disk         details
#0   running   2023-09-26T11:21:30Z   1.6%   33M of 1G     213M of 1G
#1   running   2023-09-26T11:21:30Z   1.6%   32.7M of 1G   213M of 1G

Alternatively used the Procfile

web: nginx -p /home/vcap/app -c ./nginx.conf
worker: node server.js

We got the same error.

If we comment the resolver and listen port in the nginx.conf, that both process will be running but it is quite obvious it will not solve our purpose.

Please confirm where necessary:

  • I have included a log output
  • My log includes an error message
  • I have included steps for reproduction

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the nginx.conf, manifest.yml processes configuration, and Procfile shown in the report, then reproduce the deployment using the listed Cloud Foundry and CF CLI versions. Trace how the nginx buildpack handles the resolver and listen directives; done means the nginx web process and Node.js worker processes both start without configuration errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
nginx, node.js
Domain
cloud, devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.