Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Mar 102010
 

How many worker_processes should I use in Nginx?

Answer:

In the Nginx configuration (nginx.conf), the default worker_processes is 1.

e.g.

worker_processes  1;

However, as nowadays most servers are multi-core/multi-processor machine, it is a waste to only use 1 worker process.

The recommended worker_processes is equal to the number of CPU cores, e.g. if you have a dual Quad Core server, you should set to 8.

worker_processes  8;
Feb 092010
 

How to define variable in nginx

Answer:

nginx provided a very simple way to define custom variable, which can provide a very flexible way to control your web server.

E.g.

set $foo bar; 

if ($foo ~ bar) {
    # do something  
}

Feb 092010
 

Add custom HTTP header by nginx

Answer:

To inject custom HTTP header into the HTTP response, is very easy with nginx.

Add the following line into the configuration (add into the location you need):

E.g.

location / {
    add_header Foo Bar;
}