例子
user www www;
worker_processes 2;
error_log /var/log/nginx-error.log info;
events {
use kqueue;
worker_connections 2048;
}
main
语法 | 默认 | 描述 |
---|---|---|
daemon on | off; | on | daemon |
debug_points abort | stop; | — | debug |
env variable[=value]; | TZ; | 默认nginx会移除所有环境变量,这里可以设置环境变量 |
error_log file [level]; | logs/error.log error; | 日志文件,还可以用于http,mail,stream,server.location |
events { … } | — | 连接设置 |
include file | mask; | 包含另一个conf文件(可用于其他所有块指令) | |
load_module file; | — | 加载其他模块 |
lock_file file; | logs/nginx.lock; | ? |
master_process on | off; | on | |
pcre_jit on | off; | off | jit编译,提高正则表达式的解析 |
pid file; | logs/nginx.pid | 指定存放pid信息 |
ssl_engine device; | — | Defines the name of the hardware SSL accelerator |
thread_pool name threads=number [max_queue=number]; | default threads=32 max_queue=65536; | 线程池 |
timer_resolution interval; | — | |
user user [group]; | nobody nobody; | 设置用户(user)和分组(group),分组可以不填,使用user所在的组 |
worker_cpu_affinity auto [cpumask]; | — | |
worker_priority number; | 0 | worker的优先级 |
worker_processes number | auto; | 1 | worker的最大数量 |
worker_rlimit_core size; | — | Changes the limit on the largest size of a core file (RLIMIT_CORE) for worker processes. |
worker_rlimit_nofile number; | — | Changes the limit on the maximum number of open files (RLIMIT_NOFILE) for worker processes. |
worker_shutdown_timeout time; | — | When the time expires, nginx will try to close all the connections currently open to facilitate shutdown. |
working_directory directory; | — | Defines the current working directory for a worker process. |
1.mian一般只配置一个user,默认user是nobody group是nobody,可以改成特定用户的名字,比如root root,或者其他用户名
2.nobody只有读的权限(既权限中的other中设置可读的文件)
3.root可以监听小于1024的端口(web一般都是80),普通用户和nobody都不行
event
语法 | 默认 | 描述 |
---|---|---|
accept_mutex on | off; | off | 如果no,则加锁所有worker顺序访问 |
accept_mutex_delay time; | 500ms | 当另一个worker接收连接后,下一个接收连接的延迟 |
debug_connection address | CIDR | unix:; | — | 为指定客户端开启debug |
multi_accept on | off; | off | 关闭时,每个worker一次接受一个连接,开启每个worker一次接收多个连接 |
use method; | — | |
worker_aio_requests number; | 32 | |
worker_connections number; | 512 | 最大的连接数 |
参考:
http://nginx.org/en/docs/ngx_core_module.html