nginx 由配置文件中指定的指令控制的模块组成,指令分为和。
简单指令由名称和参数组成,以空格分隔并以分号 (;) 结尾,例如:
worker_processes 3;
上面定义了 nginx 工作进程数量为 3。
块指令与简单指令具有相同的结构,但它以一组由大括号({ 和})包围的附加指令结尾,而不是分号。如果块指令可以在大括号内包含其他指令,则称为上下文(例如:events、http、server 和 location)。
例如:定义一个 server 快指令,该指令中包含了 location 块指令。配置如下:
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
}配置文件中放置在任何上下文之外的指令被认为是在主上下文中。events 和 http 指令驻留在主上下文中,server 在 http 中,location 在 server 中。例如:
worker_processes 3;
events {
worker_connections 1024;
}
http {
# 我是一行注释
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
}
}注意:# 符号后的其余行被视为注释。