Improving nginx’s performance in Docker

Recently I found that the official Nginx docker image caused a situation where the web server drops a request after some time. So I implemented the fix I did from nginx-letsencrypt in the Docker image I used.

The problem [I suspect] is found in the line worker_processes 1;. The nginx supports `auto` but it causes a few issues in the docker environment. Because it would take the number of CPUs in the host PC which is not what we would want, but we need the one from the `cgroup`

In short I had to create an init script that modifies the `worker_processes` value before the application starts.

NUMPROCS=$(cat /sys/fs/cgroup/cpuacct/cpuacct.usage_percpu | wc -w)
sed -i \
  "s/worker_processes\\s\\+1;/worker_processes ${NUMPROCS};/" \
exec nginx -g "daemon off;"