Nginx common Configuration
This is the blog how to configure a nginx
web server. It covers most important configurations, their meanings and the recommender
values.
CORE module configuration:
This section of configurations apply to the
core (global) nginx module.
user [user-id];
This configuration item is to specify what
OS user the nginx worker process is running. Usually you should specify a separated
user just for running nginx, usually it is an none-login user for security
concern. eg. user nginx;
worker_processes
[number];
this is for the number of worker_processes;
for a multiple CPU/core system, it should be configure to be equal to the
number of CPUs or cores. If the web server serves the static pages and needs
lots of IO, the number should be increased as when the thread/process will be
blocked and you need more process/thread to serve new requests.
the picture shows how the processes look like when configured as
user nginx;
worker_processes 2;
the picture shows how the processes look like when configured as
user nginx;
worker_processes 2;
worker_cpu_affinity
cpumask;
the configuration is worked with the worker_processes configuration item.
This is combined the work processes to the sepeicfied CPU, this affinity
ability is just used for the SMP architecture, not suitable for
hyper-threading.
eg. worker_cpu_affinity 0001 0010 0100
1010. the above configuration combine the first process to CPU1, second to
CPU2, third to CPU3, forth to CPU2/CPU4.
pid logs/nginx.pid;
stores the pid number for the nginx master
process
you can use the command # kill `cat
$NGINX_HOME/logs/nginx.pid` to stop the nginx.
Events module
This section is used for the events
worker_connections
[number]:
it defines how many connections a worker
process can accept. Usually 1024 is a good value for a normal load system.
use [select|epoll|etc]
it defines what the multiple threading
module, in linux system, usually epoll is a good choice and in windows, it can
only use select.
HTTP module
http module is the essential configuration
of a nginx web server. It defines the http server and its’ virtual hosts.
[TBC]
No comments:
Post a Comment