worker_processes 1;
daemon off;
error_log <%= ENV["APP_ROOT"] %>/nginx/logs/error.log;
events { worker_connections 1024; }
http {
log_format cloudfoundry '$http_x_forwarded_for - $http_referer - [$time_local] "$request" $status $body_bytes_sent';
access_log <%= ENV["APP_ROOT"] %>/nginx/logs/access.log cloudfoundry;
default_type application/octet-stream;
include mime.types;
sendfile on;
gzip on;
tcp_nopush on;
keepalive_timeout 30;
server {
listen <%= ENV["PORT"] %>;
location / {
root <%= ENV["APP_ROOT"] %>/public;
try_files $uri $uri/ /index.html =404;
index index.html index.htm Default.htm;
}
}
}
-----> Configuring nginx **WARNING** overriding nginx.conf is deprecated and highly discouraged, as it breaks the functionality of the Staticfile and Staticfile.auth configuration directives. Please use the NGINX buildpack available at: https://github.com/cloudfoundry/nginx-buildpack Exit status 0 Uploading droplet, build artifacts cache... Uploading droplet... Uploading build artifacts cache... Uploaded build artifacts cache (2.5M) Waiting for app nginx-test to start... Instances starting... Instances starting... Instances starting... Instances starting... Instances starting... Instances starting... Instances starting... Instances starting... Instances starting..
[APP/PROC/WEB/0] ERR + /home/vcap/app/start_logging.sh 2023-08-10T16:21:57.45-0400
[APP/PROC/WEB/0] ERR + nginx -p /home/vcap/app/nginx -c /home/vcap/app/nginx/conf/nginx.conf 2023-08-10T16:21:57.46-0400
[APP/PROC/WEB/0] ERR 2023/08/10 20:21:57 [emerg] 95#0: invalid log level "ENV["APP_ROOT"]" in /home/vcap/app/nginx/conf/nginx.conf:4 2023-08-10T16:22:57.49-0400
[HEALTH/0] ERR Timed out after 1m0s (30 attempts) waiting for readiness check to succeed: failed to make TCP connection to 10.255.151.201:8080: dial tcp 10.255.151.201:8080: connect: connection refused 2023-08-10T16:22:57.49-0400
[CELL/0] ERR Failed after 1m0.314s: readiness health check never passed. 2023-08-10T16:22:57.49-0400
[CELL/SSHD/0] OUT Exit status 0 2023-08-10T16:23:13.88-0400
[CELL/0] OUT Cell b87d02d7-54d6-4c9c-826f-f8b08937dd61 stopping instance 44a07a32-48d4-4bd0-6d0d-a53b 2023-08-10T16:23:13.88-0400
[CELL/0] OUT Cell b87d02d7-54d6-4c9c-826f-f8b08937dd61 destroying container for instance 44a07a32-48d4-4bd0-6d0d-a53b 2023-08-10T16:23:13.91-0400
[API/0] OUT Process has crashed with type: "web" 2023-08-10T16:23:13.94-0400
[API/0] OUT App instance exited with guid 3b48dff6-3db6-4210-9a65-a75a886636ef payload: {"instance"=>"44a07a32-48d4-4bd0-6d0d-a53b", "index"=>0, "cell_id"=>"b87d02d7-54d6-4c9c-826f-f8b08937dd61", "reason"=>"CRASHED", "exit_description"=>"Instance never healthy after 1m0.314s: Timed out after 1m0s (30 attempts) waiting for readiness check to succeed: failed to make TCP connection to 10.255.151.201:8080: dial tcp 10.255.151.201:8080: connect: connection refused; process did not exit", "crash_count"=>3, "crash_timestamp"=>1691698993874934340, "version"=>"3e44d709-bb7b-42ff-9719-efbd575c8ca9"} 2023-08-10T16:23:14.00-0400
[PROXY/0] OUT Exit status 137 2023-08-10T16:23:14.51-0400
[CELL/0] OUT Cell b87d02d7-54d6-4c9c-826f-f8b08937dd61 successfully destroyed container for instance 44a07a32-48d4-4bd0-6d0d-a53bProduct Version:
4.x
5.x
6.x
10.x
ssi: enabled pushstate: enabled host_dot_files: d # BasicAuth: enabled force_https:true http_strict_transport_security: true
worker_processes 1;
daemon off;
error_log /home/vcap/app/nginx/logs/error.log;
events { worker_connections 1024; }
http {
charset utf-8;
log_format cloudfoundry '$http_x_forwarded_for - $http_referer - [$time_local] "$request" $status $body_bytes_sent';
access_log /home/vcap/app/nginx/logs/access.log cloudfoundry;
default_type application/octet-stream;
include mime.types;
sendfile on;
gzip on;
gzip_disable "msie6";
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gunzip on;
gzip_static always;
gzip_types text/plain text/css text/js text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/xml+rss;
gzip_vary on;
tcp_nopush on;
keepalive_timeout 30;
port_in_redirect off; # Ensure that redirects don't include the internal container PORT - 8080
server_tokens off;
map $http_x_forwarded_host $best_host {
"~^([^,]+),?.*$" $1;
'' $host;
}
map $http_x_forwarded_prefix $best_prefix {
"~^([^,]+),?.*$" $1;
'' '';
}
map $http_x_forwarded_proto $best_proto {
"~^([^,]+),?.*$" $1;
'' '';
}
server {
listen 8080;
server_name localhost;
root /home/vcap/app/public;
if ($best_proto != "https") { return 301 https://$best_host$best_prefix$request_uri; }
location / {
index index.html index.htm Default.htm;
}
location ~ /\. {
deny all;
return 404;
}
}
}
It would be best to test to see if the dynamically generated nginx.conf file by the Staticfile works in a way so that the application itself functions properly. If not, it may be advisable to consider workaround 2 which is listed below. worker_processes 1;
daemon off;
error_log <%= ENV["APP_ROOT"] %>/nginx/logs/error.log;
events { worker_connections 1024; }
http {
log_format cloudfoundry '$http_x_forwarded_for - $http_referer - [$time_local] "$request" $status $body_bytes_sent';
access_log <%= ENV["APP_ROOT"] %>/nginx/logs/access.log cloudfoundry;
default_type application/octet-stream;
include mime.types;
sendfile on;
gzip on;
tcp_nopush on;
keepalive_timeout 30;
server {
listen <%= ENV["PORT"] %>;
location / {
root <%= ENV["APP_ROOT"] %>/public;
try_files $uri $uri/ /index.html =404;
index index.html index.htm Default.htm;
}
}
}
NOTE: In the nginx.conf.erb file above, if we get an error in the application logs regarding mime.types, we can comment out the "include mime.types;" entry by replacing it with "#include mime.types;" via using a hashtagweb: mkdir -p /home/vcap/app/nginx/logs && erb nginx.conf.erb | tee nginx.conf && varify -buildpack-yml-path ./buildpack.yml ./nginx.conf $HOME/modules $DEP_DIR/nginx/modules && nginx -p $PWD -c ./nginx.conf
# This conf isn't really used.
# This is to trick the nginx_buildpack's staging::ValidateNginxConf()
# to consider this a valid app
events {}
http {
server {
listen {{port}};
}
}
---
applications:
- name: nginxtest3
env:
APP_ROOT: "/home/vcap/app"
FORCE_HTTPS: 'false'
buildpacks:
- ruby_buildpack
- nginx_buildpack
stack: cflinuxfs3
processes:
- type: web
instances: 1
memory: 1024M
disk_quota: 1024M
log-rate-limit-per-second: 16K
health-check-type: port
Note that we MUST have the ruby_buildpack placed above the nginx_buildpack in the manifest.yml as we need to have the ERB templating run first before the nginx buildpack verification. cf push -f ./manifest.yml
cf logs $APP_NAME --recent