首页 > 代码库 > nginx学习笔记
nginx学习笔记
- Nginx概述
Nginx是一个高性能的http服务器和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。
Ngnix开源、免费、高性能、可靠,配置简单、资源消耗小、拥有丰富的扩展模块。
不像传统的服务器,Nginx不依赖于线程去处理requests,而是使用更易于伸缩的事件驱动(异步的)体系结构。This architecture uses small, but more importantly, predictable amounts of memory under load.即使你不需要处理成千上万的并发请求,你依然可以使用Nginx的高性能与较小的内存消耗的特点。Nginx的伸缩性是全方位的,从最小的VPS到大规模集群。
Nginx拥有一个master进程和多个worker进程,
master进程:读取和设置配置文件,以及管理worker进程
worker进程:实际处理request
Nginx通过基于事件的模型和操作系统依赖机制来实现在worker进程中高效的派发requests。(nginx employs event-based model and OS-dependent mechanisms to efficiently distribute requests among worker processes.)
Nginx以及它的模块的工作方式有配置文件决定。 - Nginx配置文件
配置文件的结构:
Nginx的组成模块由配置文件中申明的配置项控制。配置项分为简单配置项和块配置项。一个简单配置项有name以及用空格分离的parameters以及用来结尾的“;”组成。一个块配置项拥有和简单配置项类似的结构,不过不同的是它是以用({和})包围的一集合的附加命令取代“;”结尾。如果一个块配置项在它的({、})拥有其他的配置项,它被称作一个上下文。
不放在任何contexts中的配置项被认为处于main context中,因此 events 和 http 配置项处于main context中,server处于http上下文中,location处于server上下文中。
余下的以#开头的部分被认为是注释。nginx consists of modules which are controlled by directives specified in the configuration file. Directives are divided into simple directives and block directives. A simple directive consists of the name and parameters separated by spaces and ends with a semicolon (
;
). A block directive has the same structure as a simple directive, but instead of the semicolon it ends with a set of additional instructions surrounded by braces ({
and}
). If a block directive can have other directives inside braces, it is called a context (examples: events, http, server, and location).Directives placed in the configuration file outside of any contexts are considered to be in the main context. The
events
andhttp
directives reside in themain
context,server
inhttp
, andlocation
inserver
.The rest of a line after the
#
sign is considered a comment. - a
- a
nginx学习笔记