Nginx常用配置详解(一)——主配置块篇


本文依照nginx官方站点文档介绍常用的nginx各种常用配置,未经过校对,如有错误还望海涵。Nginx最基本的配置语法Nginx配置分为各个配置块。主配置块负责全局配置,各个子块都会继承全局配置。各个子块也各有不同的配置项。主配置按功能分为四类:正常运行必备的配置优化性能相关的配置用于调试及定位问题的相关的配置事件驱动相关的配置Defines user and group credentials used by worker processes. If group is omitted, a group whose name equals that of user is used.
定义worker进程使用的用户或者组的凭证,省略组名表示组名与用户名相同。Defines a file that will store the process ID of the main process.
指定存储nginx matser进程ID的文件路径。Includes another file, or files matching the specified mask, into configuration. Included files should consist of syntactically correct directives and blocks.
配置文件可嵌入其他配置文件,include指明嵌入的文件位置可以是明确的文件名,也可以是含有通配符的文件名。(include可以是绝对路径也可以是相对路径,相对路径为相对Nginx配置文件的路径,即Nginx.conf所在目录)Loads a dynamic module.
加载动态模块。此指令只在ngnix 1.9.11 版本后生效Defines the number of worker processes.The optimal value depends on many factors including (but not limited to) the number of CPU cores, the number of hard disk drives that store data, and load pattern. When one is in doubt, setting it to the number of available CPU cores would be a good start (the value “auto” will try to autodetect it).
定义worker进程数量。该设定会直接影响性能,最佳值取决于多种因素包括但不限于CPU核心、存书数据的硬盘数量,加载模式。较好的选择是设定该值值等于可用的CPU数量(auto自动检测CPU核心数量并以此为该项的设定值)。Binds worker processes to the sets of CPUs. Each CPU set is represented by a bitmask of allowed CPUs. There should be a separate set defined for each of the worker processes. By default, worker processes are not bound to any specific CPUs.
将设定的CPU核心与worker进程绑定,每个CPU设定用位掩码分别绑定给每一个worker进程。默认情况下worker进程不绑定在任何一个CPU上。(每一位CPUmask代表一个CPU核心)
例如:
主机有四个核心,建立四个worker进程分别绑定在每个CPU上主机有四个核心,建立两个worker进程,第一个进程绑定在CPU0/CPU2上,第二个进程绑定在CPU1/CPU3上使用自动自动绑定自动绑定并限制CPU使用Defines the scheduling priority for worker processes like it is done by the nice command: a negative number means higher priority. Allowed range normally varies from -20 to 20.
定义worker进程的优先级,相当于nice指令:负数的优先级更高,取值范围从-20到20。Changes the limit on the maximum number of open files (RLIMIT_NOFILE) for worker processes. Used to increase the limit without restarting the main process.
修改worker进程能打开文件的最大值,可以在不重启主进程的情况下增加限制。Determines whether nginx should become a daemon. Mainly used during development.
决定nginx是否成为守护进程,主要用于开发期间。Determines whether worker processes are started. This directive is intended for nginx developers.
决定是否启用worker进程。此指令打算给nginx开发者使用。Configures logging. Several logs can be specified on the same level (1.5.2). If on the main configuration level writing a log to a file is not explicitly defined, the default file will be used.The first parameter defines a file that will store the log. The special value stderr selects the standard error file. Logging to syslog can be configured by specifying the “syslog:” prefix. Logging to a cyclic memory buffer can be configured by specifying the “memory:” prefix and buffer size, and is generally used for debugging (1.7.11).The second parameter determines the level of logging, and can be one of the following: debug, info, notice, warn, error, crit, alert, or emerg. Log levels above are listed in the order of increasing severity. Setting a certain log level will cause all messages of the specified and more severe log levels to be logged. For example, the default level error will cause error, crit, alert, and emerg messages to be logged. If this parameter is omitted then error is used.
配置日志,几个日志可以被指定为同一级别。如果主配置文件级别中配置文件路径没有明确指明,则使用默认配置。第一个字段定义日志存储文件位置。特殊值stderr选择标准错误文件。针对syslog的文件可以在前面用syslog:指明。针对cyclic memory buffer可以在前面用memory:指明,并且要指明缓冲大小,此项指令通常用于调试。第二字段判定日志级别,在debug, info, notice, warn, error, crit, alert, emerg之中选择一项。这些日志级别从左到右依次从轻微到严重。确定日志级别后,会记录该级别和该级别以上的级别的所有日志。例如:设定error级别会记录error, crit, alert, emerg四个基本,如果该条目省略,则默认级别为error。事件驱动相关的配置配置与events配置块中Sets the maximum number of simultaneous connections that can 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 simultaneous connections cannot exceed the current l开发云主机域名imit on the maximum number of open files, which can be changed by worker_rlimit_nofile.
设定worker进程同步连接最大值。这项设定需要注意,这个数字包括了所有连接(例如:代理连接服务器等),不仅仅是客户端的连接。
另一个值得注意的问题是实际的同步连接数值要小于之前在worker_rlimit_nofile中设定的open file值。Specifies the connection processing method to use. There is normally no need to specify it explicitly, because nginx will by default use the most efficient method.
指明使用的连接进程方法。通常不需要明确的指明,因为NGINX默认会使用最有效的方法。If accept_mutex is 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 processes may just waste system resources.
如果accept_mutex启用,worker进程在接受新连接时采取轮流进行的模式。如果不这么设定,新连接将不会通知给各worker进程。在新连接较少的情况下,部分worker进程资源将被浪费。If accept_mutex is enabled, specifies the maximum time during which a worker process will try to restart accepting new connections if another worker process is currently accepting new connections.
accept_mutex启用的情况下,指明在其他worker进程正在接受新连接时,worker进程重新接受新连接的超时时间。

相关推荐: linux创建软链接失败是什么原因造成的

本篇文章和大家了解一下linux创建软链接失败是什么原因造成的。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。举例说明:对/Devops/live-student/目录下的test文件夹做软链接,如果连接目的路径与源文件相同,即/Devops…

免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。

(0)
打赏 微信扫一扫 微信扫一扫
上一篇 04/02 12:19
下一篇 04/02 12:19