关于nginx的几个核心配置说明
2016-08-02 12:14
483 查看
http://blog.csdn.net/delphiwcdj/article/details/35787517
学习和使用nginx,首先需要了解nginx的配置选项的含义,比较好的学习方法是,先保存复制一份默认的nginx.conf配置,然后开始动手修改自己感兴趣的配置,尝试各种功能。在遇到配置错误时,nginx可以很友好地给我们做出提示:
比如在添加配置时少一个分号,nginx会提示如下的错误信息:
[plain] view
plain copy
print?
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
root@mba:sbin#./nginx
nginx: [emerg] directive "daemon" is not terminated by ";" in /Users/gerryyang/LAMP/nginx/install/nginx-1.7.2/conf/nginx.conf:19
比如在Mac OS X上指定event为epoll时,会提示如下错误信息:
[plain] view
plain copy
print?
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
root@mba:sbin#./nginx
nginx: [emerg] invalid event type "epoll" in /Users/gerryyang/LAMP/nginx/install/nginx-1.7.2/conf/nginx.conf:14
下面是nginx几个核心的配置说明:
If
The use of rtsig connection processing methodrequires
If accept_mutex is enabled, specifies the maximum timeduring which a worker process will try to restart
accepting newconnections if another worker process is currently acceptingnew connections.
connection processing method can be selectedexplicitly with the use directive.
The following connection processing methods are supported:
or disable the build of this module.
the build of this module.
Some older distributions like SuSE 8.2 provide patchesthat add epoll support to 2.4 kernels.
parameter.However, in Linux 2.6.6-mm2 this parameter is gone, and each processnow has its own event queue.The size of each queue is limited by
On queue overflow, nginx discards the queue and falls back to
Then the
The nginx binary version for Windows is always built with the debugging logsupport, so only setting the
Note that redefining the log without also specifying the
disables the debugging log for this server:
To avoid this, either the line redefining the log should becommented out, or the
It is also possible to enable the debugging log for selected client addresses only:
Provides the configuration file context in which the directives thataffect connection processing are specified.
(5) include说明
Includes another
Usage example:
(6) lock_file说明
nginx uses the locking mechanism to implement accept_mutex and serialize access to shared memory.On most
systems the locks are implemented using atomic operations,and this directive is ignored.On other systems the “lock file” mechanism is used.This directive specifies a prefix for the names of lock files.
(7) master_process说明
Determines whether worker processes are started.This directive is intended for nginx developers.
If
The directive is ignored if kqueue connection processing method is used, because it reportsthe number of new connections
waiting to be accepted.
The use of rtsig connection processing methodautomatically enables
Defines a
Specifies the connection processing
because nginx willby default use the most efficient method.
Defines
Sets the maximum number of simultaneous connections thatcan be opened by a worker process.
It should be kept in mind that this number includes all connections(e.g. connections with proxied servers, among others),not only connections with clients.Another consideration is that the actual number of simultaneousconnections cannot exceed the current limit
onthe maximum number of open files, which can be changed byworker_rlimit_nofile.
Defines the number of worker processes.
The optimal value depends on many factors including (but notlimited to) the number of CPU cores, the number of hard diskdrives that store data, and load pattern.When one is in doubt, setting it to the number of available CPU coreswould be a good start (the
value “
The
Changes the limit on the largest size of a core file(
Changes the limit on the maximum number of open files(
On systems that support rtsig connection processing method,changes the limit on the number of signals that may be queued(
for worker processes.Used to increase the limit without restarting the main process.
Defines the current working directory for a worker process.It is primarily used when writing a core-file, in which casea worker process should have write permission for thespecified directory.
参考
[1] http://wiki.nginx.org/GettingStarted
[2] http://wiki.nginx.org/NginxModules
[3] http://wiki.nginx.org/NginxConfiguration
[4] http://blog.martinfjordvald.com/2010/07/nginx-primer/
[5] http://blog.martinfjordvald.com/2012/08/understanding-the-nginx-configuration-inheritance-model/
学习和使用nginx,首先需要了解nginx的配置选项的含义,比较好的学习方法是,先保存复制一份默认的nginx.conf配置,然后开始动手修改自己感兴趣的配置,尝试各种功能。在遇到配置错误时,nginx可以很友好地给我们做出提示:
比如在添加配置时少一个分号,nginx会提示如下的错误信息:
[plain] view
plain copy
print?
![](https://code.csdn.net/assets/CODE_ico.png)
root@mba:sbin#./nginx
nginx: [emerg] directive "daemon" is not terminated by ";" in /Users/gerryyang/LAMP/nginx/install/nginx-1.7.2/conf/nginx.conf:19
比如在Mac OS X上指定event为epoll时,会提示如下错误信息:
[plain] view
plain copy
print?
![](https://code.csdn.net/assets/CODE_ico.png)
root@mba:sbin#./nginx
nginx: [emerg] invalid event type "epoll" in /Users/gerryyang/LAMP/nginx/install/nginx-1.7.2/conf/nginx.conf:14
下面是nginx几个核心的配置说明:
(1) accept_mutex的说明
Syntax: | accept_mutex;[/code]on| [code]off |
---|---|
Default: | accept_mutex on; |
Context: | events |
accept_mutexis enabled,worker processes will accept new connections by turn.Otherwise, all worker processes will be notified about new connections,and if volume of new connections is low, some of the worker processesmay just waste system resources.
The use of rtsig connection processing methodrequires
accept_mutexto be enabled.
Syntax: | accept_mutex_delaytime; |
---|---|
Default: | accept_mutex_delay 500ms; |
Context: | events |
accepting newconnections if another worker process is currently acceptingnew connections.
(2) Connections processing methods的说明
nginx supports a variety of connection processing methods.The availability of a particular method depends on the platform used.On platforms that support several methods nginx will normallyselect the most efficient method automatically.However, if needed, aconnection processing method can be selectedexplicitly with the use directive.
The following connection processing methods are supported:
select— standard method.The supporting module is built automatically on platforms that lackmore efficient methods.The
--with-select_moduleand
--without-select_moduleconfiguration parameterscan be used to forcibly enable
or disable the build of this module.
poll— standard method.The supporting module is built automatically on platforms that lackmore efficient methods.The
--with-poll_moduleand
--without-poll_moduleconfiguration parameterscan be used to forcibly enable or disable
the build of this module.
kqueue— efficient method used onFreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0, and Mac OS X.
epoll— efficient method used onLinux 2.6+.
Some older distributions like SuSE 8.2 provide patchesthat add epoll support to 2.4 kernels.
rtsig— real time signals, efficient methodused on Linux 2.2.19+.By default,the system-wide event queue is limited by 1024 signals.On loaded servers it may become necessary to increase this limitby changing the
/proc/sys/kernel/rtsig-maxkernel
parameter.However, in Linux 2.6.6-mm2 this parameter is gone, and each processnow has its own event queue.The size of each queue is limited by
RLIMIT_SIGPENDINGand can be changed with worker_rlimit_sigpending.
On queue overflow, nginx discards the queue and falls back to
pollconnection processing method untilthe situation gets back to normal.
/dev/poll— efficient method used onSolaris 7 11/99+, HP/UX 11.22+ (eventport), IRIX 6.5.15+,and Tru64 UNIX 5.1A+.
eventport— event ports, efficient methodused on Solaris 10.
(3) A debugging log说明
To enable a debugging log, nginx needs to be configured to supportdebugging during the build:./configure --with-debug ...
Then the
debuglevel should be set with the error_log directive:
error_log /path/to/log debug;
The nginx binary version for Windows is always built with the debugging logsupport, so only setting the
debuglevel will suffice.
Note that redefining the log without also specifying the
debuglevel will disable the debugging log.In the example below, redefining the log on the serverlevel
disables the debugging log for this server:
error_log /path/to/log debug;
http {
server {
error_log /path/to/log;
...
To avoid this, either the line redefining the log should becommented out, or the
debuglevel specification shouldalso be added:
error_log /path/to/log debug;
http {
server {
error_log /path/to/log debug;...
It is also possible to enable the debugging log for selected client addresses only:
error_log /path/to/log; events { debug_connection 192.168.1.1; debug_connection 192.168.10.0/24; }
(4) event说明
Syntax: | events { ... } |
---|---|
Default: | — |
Context: | main |
(5) include说明
Syntax: | include;[/code]file| [code]mask |
---|---|
Default: | — |
Context: | any |
file, or files matching thespecified
mask, into configuration.Included files should consist of syntactically correct directives and blocks.
Usage example:
include mime.types; include vhosts/*.conf;
(6) lock_file说明
Syntax: | lock_filefile; |
---|---|
Default: | lock_file logs/nginx.lock; |
Context: | main |
systems the locks are implemented using atomic operations,and this directive is ignored.On other systems the “lock file” mechanism is used.This directive specifies a prefix for the names of lock files.
(7) master_process说明
Syntax: | master_process;[/code]on| [code]off |
---|---|
Default: | master_process on; |
Context: | main |
(8) multi_accept说明
Syntax: | multi_accept;[/code]on| [code]off |
---|---|
Default: | multi_accept off; |
Context: | events |
multi_acceptis disabled, a worker processwill accept one new connection at a time.Otherwise, a worker processwill accept all new connections at a time.
The directive is ignored if kqueue connection processing method is used, because it reportsthe number of new connections
waiting to be accepted.
The use of rtsig connection processing methodautomatically enables
multi_accept.
(9) pid说明
Syntax: | pidfile; |
---|---|
Default: | pid nginx.pid; |
Context: | main |
filethat will store the process ID of the main process.
(10) use说明
Syntax: | usemethod; |
---|---|
Default: | — |
Context: | events |
methodto use.There is normally no need to specify it explicitly,
because nginx willby default use the most efficient method.
(11) user说明
Syntax: | user];[/code]user[[code]group |
---|---|
Default: | user nobody nobody; |
Context: | main |
userand
groupcredentials used by worker processes.If
groupis omitted, a group whose name equalsthat of
useris used.
(12) worker_connections说明
Syntax: | worker_connectionsnumber; |
---|---|
Default: | worker_connections 512; |
Context: | events |
It should be kept in mind that this number includes all connections(e.g. connections with proxied servers, among others),not only connections with clients.Another consideration is that the actual number of simultaneousconnections cannot exceed the current limit
onthe maximum number of open files, which can be changed byworker_rlimit_nofile.
(13) worker_processes说明
Syntax: | worker_processes;[/code]number| [code]auto |
---|---|
Default: | worker_processes 1; |
Context: | main |
The optimal value depends on many factors including (but notlimited to) the number of CPU cores, the number of hard diskdrives that store data, and load pattern.When one is in doubt, setting it to the number of available CPU coreswould be a good start (the
value “
auto”will try to autodetect it).
The
autoparameter is supported starting fromversions 1.3.8 and 1.2.5.
(14) worker_rlimit_core说明
Syntax: | worker_rlimit_coresize; |
---|---|
Default: | — |
Context: | main |
RLIMIT_CORE) for worker processes.Used to increase the limit without restarting the main process.
(15) worker_rlimit_nofile说明
Syntax: | worker_rlimit_nofilenumber; |
---|---|
Default: | — |
Context: | main |
RLIMIT_NOFILE) for worker processes.Used to increase the limit without restarting the main process.
(16) worker_rlimit_sigpending说明
Syntax: | worker_rlimit_sigpendingnumber; |
---|---|
Default: | — |
Context: | main |
RLIMIT_SIGPENDING)
for worker processes.Used to increase the limit without restarting the main process.
(17) working_directory说明
Syntax: | working_directorydirectory; |
---|---|
Default: | — |
Context: | main |
参考
[1] http://wiki.nginx.org/GettingStarted
[2] http://wiki.nginx.org/NginxModules
[3] http://wiki.nginx.org/NginxConfiguration
[4] http://blog.martinfjordvald.com/2010/07/nginx-primer/
[5] http://blog.martinfjordvald.com/2012/08/understanding-the-nginx-configuration-inheritance-model/
相关文章推荐
- 关于nginx的几个核心配置说明
- Spring MVC 教程,快速入门,深入分析――关于写几个配置文件的说明
- Nginx—核心配置location匹配规则说明
- 关于Nginx的详细说明和配置
- 关于AT New的几个说明
- 关于AT New的几个说明
- 关于:web.config 的配置说明
- 关于使用Spring和hibernate开发web程序的配置说明和简单实例的详细说明
- 一篇关于web.xml配置的详细说明
- 关于web.xml配置的详细说明
- [转]关于安装配置XNA开发环境的详细说明
- [原创]关于MRTG的几个全局关键字的说明
- SD-- SAP定义的几个标准Cost Condition的说明和科目配置
- 关于__cdecl,__fastcall与__stdcall 等几个关键字的说明
- 一篇关于web.xml配置的详细说明
- 关于AT New的几个说明
- [导入]关于:web.config 的配置说明
- 关于在Solaris上进行配置Oracle环境的JDBC的方法的说明
- 一篇关于web.xml配置的详细说明
- 关于 asp.net 服务器控件几个 ID 的说明