Auto detect the number of CPU's and set worker_processes

Maxim Dounin mdounin at
Mon Sep 17 09:43:28 UTC 2012


On Sat, Sep 15, 2012 at 07:55:49PM -0400, justin wrote:

> I am trying to get fancy and have `nginx.conf` auto-detect the number of
> CPU's on the server and then set `worker_processes` to that number. Here is
> what I have:
>     worker_processes $(cat /proc/cpuinfo | grep "processor" | sort -u | wc
> -l);
> Unfortunately, that is throwing an error on nginx start. Is it even possible
> to run shell commands from inside nginx configuration files?

No, it's not currently supported.  You may try e.g. make + sed (or 
any other templating system) to do this, as well as many other 
macro-expansion related things.

Maxim Dounin

More information about the nginx mailing list