nginx-主模块

Nginx主模块

这里是控制 Nginx 的基本功能的指令.

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 on|off 
默认:daemon on 
作用:守护进程是可以脱离终端并且在后台运行的进程。他脱离是为了避免进程执行过程中的信息在终端打印出来,这样一来,进程也不会被任何终端所产生的信息打断。默认,就是守护进程开启。 
不过,为了调试,所以,可以关闭。

 

debug_points

语法:debug_points [stop|abort] 
作用:这个配置用来帮助用户调试Nginx,他接收2个参数:stop和abort。Nginx在一些关键的错误逻辑中设置了调试点。如果设置为stop,那么Nginx的代码执行到这些调试点时,会发出SIGSTOP信号。如果abort,则会产生一个coredump文件。 通常不会用这个配置项。
 

error_log

语法: error_log file [ debug | info | notice | warn | error | crit ]

缺省值: ${prefix}/logs/error.log

示例 error_log  /xxx/log/nginx/error.log crit;

 

include

语法: include file | *

缺省值: none

你可以在任意地方使用include指令实现配置文件的包含,类似于apache中的include方法,可减少主配置文件d。

include /xxx/server/nginx/conf/vhosts/xxx.conf;

指令还支持像下面配置一样的全局包含的方法,例如包含一个目录下所有以".conf"结尾的文件:

include vhosts/*.conf;

注意路径受到configure编译参数--prefix=<路径>指令的影响,如果没有指定,Nginx默认是被编译在/usr/local/nginx。

 

lock_file

语法: 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.

nginx使用accept 互斥来序列化accept()系统调用。如果nginx是由GCC、英特尔C++、或SunPro C++编译器在i38、AMD64、SPARC64和PPC64上构建的,那么nginx使用原子操作来实现互斥。在其他情况下,将使用文件锁。

Nginx使用锁机制来实现 accept_mutex 以及序列化访问来实现共享内存,大多数系统使用原子操作来实现锁,那么这个指令将会被忽略,其他一些系统使用 lock file来实现锁,这个指令设置锁的名称和路径前缀。

 

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"指令,这些选项仅用于开发调试。

 

pid 

语法: pid file

缺省值: compile-time option Example:

pid /var/log/nginx.pid;

进程id存储文件。可以使用 kill -HUPcat /var/log/nginx.pid\

 

 

user

语法: user user [group]

缺省值: nobody nobody

指定Nginx Worker进程运行用户,默认是nobody帐号。

例如:

user www users;

nginx 让users有权限启动两种方法

普通用户在restart和reload nginx时,会报错:

?

1

2

the "user" directive makes sense only if the master process runs with super-user privileges,

ignored in /opt/nginx/conf/nginx.conf:1

我又不能给开发人员root权限,没办法,只好这么做。

原因是:默认情况下Linux的1024以下端口是只有root用户才有权限占用

方法一:

所有用户都可以运行(因为是755权限,文件所有者:root,组所有者:root)

?

1

2

3

4

chown root:root nginx

chmod 755 nginx

 

chmod u+s nginx

方法二:

仅 root 用户和 reistlin 用户可以运行(因为是750权限,文件所有者:root,组所有者:www)

?

1

2

3

4

5

chown root:www nginx

 

chmod 750 nginx

 

chmod u+s nginx

 

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:

该指令用于指定openssl使用的引擎。你可以通过下面的命令行获知系统目前支持的openssl引擎

openssl engine -t

SSL硬件加速

语法:ssl_engine device; 
作用:如果服务器上有SSL硬件加速设备,那么就可以进行配置以加快SSL协议的处理速度。用户可以用OpenSSL提供的命令来查看是否有SSL硬件加速设备:openssl engine -t

 

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().

仅适用于linux,使用该选项可以绑定worker进程和CPU.

实例https://blog.csdn.net/u010433704/article/details/99823680

 

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进程分配优先值。

语法:worker_priority nice; 
默认:worker_priority 0; 
作用:在Linux和Unix中,当许多进程都处于可执行状态时,按照优先级来决定本次内核选择哪一个进程执行。进程分配的CPU时间片大小也与优先级有关,优先级越高,时间片越长(例如,在默认情况下,最小时间片是5ms,最大则有800ms)。优先级由静态优先级和内核根据进程的执行情况所做的动态调整(目前只有+-5的调整)共同决定。nice是进程的优先级,他的取值范围是-20~+19,-20是最高优先级,+19是最低优先级。不建议把nice的值设为比内核进程(t通常为-5)还要小。
 

worker_processes

语法: worker_processes number

缺省值: 1

e.g.:

worker_processes 5;#一般等于cpu核数 小于等于核数*2

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

nginx可以使用多个worker进程,原因如下:

  1. to use SMP  使用SMP  https://blog.csdn.net/u010433704/article/details/99829706
  2. to decrease latency when workers blockend on disk I/O 单个worker进程容易堵塞在硬件I/O,多个进程可以减少延迟
  3. to limit number of connections per process when select()/poll() is used 当select()/poll()被调用时可以减少每个进程的连接数量

 

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

max_clients = worker_processes * worker_connections 理论计算值  https://blog.51cto.com/liuqunying/1420556

worker_connections 每一个worker进程能并发处理(发起)的最大连接数(包含所有连接数)

 

worker_rlimit_nofile

语法: worker_rlimit_nofile limit 缺省值: '

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

每个nginx进程打开文件描述符最大数目 配置要和系统的单进程打开文件数一致,linux 2.6内核下开启文件打开数为65535

理论最大值为204800,实际根据Linux系统/etc/security/limits.conf文件里面的* soft nofile和* hard nofile判断。

 

worker_rlimit_core

语法: worker_rlimit_core size

设置每个worker最大能打开的核心文件数,用于突破上限而不用重启master进程。
core文件中Nginx发生crash的时候会产生的文件。一般用于调试,gdb等。

 

working_directory

Syntax:     working_directory directory;
Default:    —
Context:    main

设定Nginx的worker进程的工作目录,仅用于定义core文件的位置,该目录必须要让Nginx的运行时用户有写的权限,一般会配套的有 worker_rlimit_core 指令设置。

 

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.

指定为调用进程的实际用户ID排队的信号数限制

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值