为了更容易维护配置,我们发起将其拆分为一组特定功能的文件,存储在 /etc/nginx/conf.d 目录中,并在主 nginx.conf 文件中使用 include 指令来引用特定功能文件的内容。
include conf.d/http;
include conf.d/stream;
include conf.d/exchange-enhanced;
复制代码
上下文
几个顶级指令,称为上下文,将适用于差别流量类型的指令分组在一起:
events – 通用毗连处置处罚
http – HTTP 流量
mail – 邮件流量
stream – TCP 和 UDP 流量
放置在这些上下文之外的指令被认为在主上下文中。
虚拟服务器
在每个流量处置处罚上下文中,您可以包含一个或多个 server 块来定义控制请求处置处罚的虚拟服务器。您可以在 server 上下文中包含的指令取决于流量类型。
对于 HTTP 流量(http 上下文),每个 server 指令控制特定域名或 IP 地址上资源的请求处置处罚。在 server 上下文中的一个或多个 location 上下文定义了怎样处置处罚特定的 URI 集。
对于邮件和 TCP/UDP 流量(mail 和 stream 上下文),每个 server 指令控制到达特定 TCP 端口或 UNIX 套接字的流量的处置处罚。
具有多个上下文的示例配置文件
以下配置说明白上下文的使用。
user nobody; # a directive in the 'main' context
events {
# configuration of connection processing
}
http {
# Configuration specific to HTTP and affecting all virtual servers
server {
# configuration of HTTP virtual server 1
location /one {
# configuration for processing URIs starting with '/one'
}
location /two {
# configuration for processing URIs starting with '/two'
}
}
server {
# configuration of HTTP virtual server 2
}
}
stream {
# Configuration specific to TCP/UDP and affecting all virtual servers