FAQ

Page Discussion Edit History

ChsHttpMainModule

Contents

[edit] Nginx Main Module

杩欓噷鏄帶鍒 Nginx 鐨勫熀鏈姛鑳界殑鎸囦护.

[edit] 鎸囦护

  • [#daemon daemon]
  • [#debug_points debug_points]
  • [#error_log error_log]
  • [#include include]
  • [#lock_file lock_file]
  • [#master_process master_process]
  • [#pid pid]
  • [#ssl_engine ssl_engine]
  • [#timer_resolution timer_resolution]
  • [#user user group]
  • [#worker_cpu_affinity worker_cpu_affinity]
  • [#worker_priority worker_priority]
  • [#worker_processes worker_processes]
  • [#worker_rlimit_core worker_rlimit_core]
  • [#worker_rlimit_nofile worker_rlimit_nofile]
  • [#worker_rlimit_sigpending worker_rlimit_sigpending]
  • [#working_directory working_directory]

Template:Anchor

[edit] daemon

璇硶: daemon on | off

缂虹渷鍊: on

daemon  off;

Do not use the "daemon" and "master_process" directives in a production mode, these options are mainly used for development only. You can use daemon off safely in production mode with runit / daemontools however you can't do a graceful upgrade. master_process off should never be used in production.

鐢熶骇鐜涓笉瑕佷娇鐢"daemon"鍜"master_process"鎸囦护锛岃繖浜涢夐」浠呯敤浜庡紑鍙戣皟璇曘

Template:Anchor

[edit] debug_points

璇硶: debug_points [stop | abort]

缂虹渷鍊: none

debug_points stop;

There are some assertion points inside nginx that allow to stop nginx to attach the debugger, or to abort and to create the core file.

搴旇閫傜敤浜庤皟璇曪紝鍦ㄨ皟璇曞櫒鍐呰缃柇鐐逛箣绫荤殑銆

Template:Anchor

[edit] error_log

璇硶: error_log file [ debug | info | notice | warn | error | crit ]

缂虹渷鍊: ${prefix}/logs/error.log

Nginx 娣诲姞 --with-debug 缂栬瘧鍙傛暟, 浣犺繕鑳藉浣跨敤浠ヤ笅閰嶇疆:

error_log LOGFILE [ debug_core | debug_alloc | debug_mutex | debug_event
]: | debug_http | debug_imap ;

Template:Anchor

[edit] include

璇硶: include file | *

缂虹渷鍊: none

浣犲彲浠ュ湪浠绘剰鍦版柟浣跨敤include鎸囦护瀹炵幇閰嶇疆鏂囦欢鐨勫寘鍚紝绫讳技浜巃pache涓殑include鏂规硶锛屽彲鍑忓皯涓婚厤缃枃浠禿銆

include 鎸囦护杩樻敮鎸佸儚涓嬮潰閰嶇疆涓鏍风殑鍏ㄥ眬鍖呭惈鐨勬柟娉曪紝渚嬪鍖呭惈涓涓洰褰曚笅鎵鏈変互".conf"缁撳熬鐨勬枃浠:

include vhosts/*.conf;

娉ㄦ剰璺緞鍙楀埌configure缂栬瘧鍙傛暟--prefix=<璺緞>鎸囦护鐨勫奖鍝嶏紝濡傛灉娌℃湁鎸囧畾锛孨ginx榛樿鏄缂栬瘧鍦/usr/local/nginx銆

Template:Anchor

璇硶: lock_file file

缂虹渷鍊: compile-time option

lock_file  /var/log/lock_file;

nginx uses accept mutex to serialize accept() syscalls. If nginx is built by gcc, Intel C++, or SunPro C++ compilers on i386, amd64, sparc64, and ppc64, then nginx uses the atomic instructions to implement the mutex. In other cases the lock file would be used.

Template:Anchor

[edit] master_process

璇硶: master_process on | off

缂虹渷鍊: on

master_process  off;

Do not use the "daemon" and "master_process" directives in a production mode, these options are mainly used for development only.

鐢熶骇鐜涓笉瑕佷娇鐢"daemon"鍜"master_process"鎸囦护锛岃繖浜涢夐」浠呯敤浜庡紑鍙戣皟璇曘

Template:Anchor

[edit] pid

璇硶: pid file

缂虹渷鍊: compile-time option Example:

pid /var/log/nginx.pid;

杩涚▼id瀛樺偍鏂囦欢銆傚彲浠ヤ娇鐢 kill -HUP cat /var/log/nginx.pid\ 瀵筃ginx杩涜閰嶇疆鏂囦欢閲嶆柊鍔犺浇銆

Template:Anchor

[edit] ssl_engine

璇硶: ssl_engine engine

缂虹渷鍊: system dependent

Here you can set your preferred openssl engine if any available. You can figure out which one do you have with the commandline tool:

璇ユ寚浠ょ敤浜庢寚瀹歰penssl浣跨敤鐨勫紩鎿庛備綘鍙互閫氳繃涓嬮潰鐨勫懡浠よ鑾风煡绯荤粺鐩墠鏀寔鐨刼penssl寮曟搸

openssl engine -t

渚嬪:

$ openssl engine -t
(cryptodev) BSD cryptodev engine
: [ available ] 
(dynamic) Dynamic engine loading support
: [ unavailable ] 

Template:Anchor

[edit] timer_resolution

璇硶: timer_resolution t

缂虹渷鍊: none

Example:

timer_resolution  100ms;

The directive allows to decrease number gettimeofday() syscalls. By default gettimeofday() is called after each return from kevent(), epoll, /dev/poll, select(), poll().

But if you need an exact time in logs when logging $upstream_response_time, or $msec variables, then you should use timer_resolution.

Template:Anchor

[edit] user

璇硶: user user [group]

缂虹渷鍊: nobody nobody

鎸囧畾Nginx Worker杩涚▼杩愯鐢ㄦ埛锛岄粯璁ゆ槸nobody甯愬彿銆

渚嬪:

user www users;

Template:Anchor

[edit] worker_cpu_affinity

璇硶: worker_cpu_affinity cpumask [cpumask...]

缂虹渷鍊: none

Linux only.

With this option you can bind the worker process to a CPU, it calls sched_setaffinity().

浠呴傜敤浜巐inux锛屼娇鐢ㄨ閫夐」鍙互缁戝畾worker杩涚▼鍜孋PU.

For example,

worker_proceses     4;
worker_cpu_affinity 0001 0010 0100 1000;

Bind each worker process to one CPU only.

鍒嗗埆缁欐瘡涓獁orker杩涚▼缁戝畾涓涓狢PU.

worker_proceses     2;
worker_cpu_affinity 0101 1010;

Bind the first worker to CPU0/CPU2, bind the second worker to CPU1/CPU3. This is suitable for HTT.

灏咰PU0/CPU2缁戝畾缁欑涓涓獁orker杩涚▼锛屽皢CPU1/CPU3缁戝畾缁欑浜屼釜worker杩涚▼銆

Template:Anchor

[edit] worker_priority

璇硶: worker_priority [-] number

缂虹渷鍊: on

With this option you can give to all worker processes the priority (nice) you need/wish, it calls setpriority().

浣跨敤璇ラ夐」鍙互缁欐墍鏈夌殑worker杩涚▼鍒嗛厤浼樺厛鍊笺

Template:Anchor

[edit] worker_processes

璇硶: worker_processes number

缂虹渷鍊: 1

e.g.:

worker_processes 5;

nginx has the ability to use more than one worker process for several reasons:

nginx鍙互浣跨敤澶氫釜worker杩涚▼锛屽師鍥犲涓嬶細

  1. to use SMP
  2. to decrease latency when workers blockend on disk I/O
  3. to limit number of connections per process when select()/poll() is used

The worker_processes and worker_connections from the event sections allows you to calculate maxclients value: k

max_clients = worker_processes * worker_connections

Template:Anchor

[edit] worker_rlimit_core

璇硶: worker_rlimit_core size

缂虹渷鍊: '

Maximum size of core file per worker;

Template:Anchor

[edit] worker_rlimit_nofile

璇硶: worker_rlimit_nofile limit 缂虹渷鍊: '

Specifies the value for maximum file descriptors that can be opened by this process.

鎸囧畾

Template:Anchor

[edit] worker_rlimit_sigpending

璇硶: worker_rlimit_sigpending limit 缂虹渷鍊: '

(Since Linux 2.6.8) Specifies the limit on the number of signals that may be queued for the real user ID of the calling process.

Template:Anchor

[edit] working_directory

璇硶: working_directory path 缂虹渷鍊: --prefix

This is the working directory for the workers. It's used for core files only. nginx uses absolute paths only, all relative paths in configuration files are relative to --prefix==PATH.

[edit] References