nginx中Nginx Main Module(主模組)配置及各個參數含義 這裡是控制 Nginx 的準系統的指令.指令:[html] [#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] www.2cto.com daemon文法: daemon on | off預設值: on[html] 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"指令,這些選項僅用於開發調試。debug_points文法: debug_points [stop | abort]預設值: none[html] 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.應該適用於調試,在調試器內設定斷點之類的。 www.2cto.com error_log文法: error_log file [ debug | info | notice | warn | error | crit ]預設值: ${prefix}/logs/error.logNginx 添加 --with-debug 編譯參數, 你還能夠使用以下配置:[html] error_log LOGFILE [ debug_core | debug_alloc | debug_mutex | debug_event ]: | debug_http | debug_imap ; include文法: include file | *預設值: none你可以在任意地方使用include指令實現設定檔的包含,類似於apache中的include方法,可減少主設定檔d。 www.2cto.com include 指令還支援像下面配置一樣的全域包含的方法,例如包含一個目錄下所有以".conf"結尾的檔案:[html] include vhosts/*.conf; 注意路徑受到configure編譯參數--prefix=<路徑>指令的影響,如果沒有指定,Nginx預設是被編譯在/usr/local/nginx。文法: lock_file file預設值: compile-time option[html] 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.www.2cto.com master_process文法: master_process on | off預設值: on[html] 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"指令,這些選項僅用於開發調試。pid文法: pid file預設值: compile-time option Example:[html] pid /var/log/nginx.pid; 進程id隱藏檔。可以使用 kill -HUP cat /var/log/nginx.pid\ 對Nginx進行設定檔重新載入。ssl_engine文法: ssl_engine engine預設值: system dependentHere you can set your preferred openssl engine if any available. You can figure out which one do you have with the commandline tool:該指令用於指定openssl使用的引擎。你可以通過下面的命令列獲知系統目前支援的openssl引擎 www.2cto.com openssl engine -t例如:[html] $ openssl engine -t (cryptodev) BSD cryptodev engine : [ available ] (dynamic) Dynamic engine loading support : [ unavailable ] timer_resolution文法: timer_resolution t預設值: noneExample:[html] timer_resolution 100ms; www.2cto.com 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.user文法: user user [group]預設值: nobody nobody指定Nginx Worker進程運行使用者,預設是nobody帳號。例如:[html] user www users; worker_cpu_affinity文法: worker_cpu_affinity cpumask [cpumask...]預設值: noneLinux only.With this option you can bind the worker process to a CPU, it calls sched_setaffinity().僅適用於linux,使用該選項可以綁定worker進程和CPU.For example,[html] worker_proceses 4; worker_cpu_affinity 0001 0010 0100 1000; Bind each worker process to one CPU only.分別給每個worker進程綁定一個CPU. www.2cto.com [html] 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.將CPU0/CPU2綁定給第一個worker進程,將CPU1/CPU3綁定給第二個worker進程。 worker_priority文法: worker_priority [-] number預設值: onWith this option you can give to all worker processes the priority (nice) you need/wish, it calls setpriority().使用該選項可以給所有的worker進程分配優先值。 worker_processes文法: worker_processes number預設值: 1e.g.:worker_processes 5;nginx has the ability to use more than one worker process for several reasons:nginx可以使用多個worker進程,原因如下:to use SMPto decrease latency when workers blockend on disk I/Oto limit number of connections per process when select()/poll() is usedThe worker_processes and worker_connections from the event sections allows you to calculate maxclients value: kmax_clients = worker_processes * worker_connections worker_rlimit_core文法: worker_rlimit_core size預設值: 'Maximum size of core file per worker; www.2cto.com worker_rlimit_nofile文法: worker_rlimit_nofile limit 預設值: 'Specifies the value for maximum file descriptors that can be opened by this process. 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.
working_directory文法: working_directory path 預設值: --prefixThis 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.