NGINX is a free,open-source,high-performance HTTP server and reverse proxy,as well as an IMAP/POP3 proxy server.
NGINX is one of a handful of servers written to address the C10K problem.Unlike traditional servers.NGINX doesn’t rely on threads to handle requests.?

Nginx的程序框架:
? ? ? master/worker
? ? ? ? ? ? ? ? 一個master進(jìn)程:
負(fù)載加載和分析配置文件、管理worker進(jìn)程、平滑升級
一個或多個worker進(jìn)程
處理并響應(yīng)用戶請求
緩存相關(guān)的進(jìn)程:
Cache loader:載入緩存對象
Cache manager:管理緩存對象
特性:異步、事件驅(qū)動和非阻塞
并發(fā)請求處理:通過epoll/select
文件IO:高級IO sendfile,異步,nmap
Nginx模塊:高度模塊化,但其模塊早期不支持DSO機制,近期版本支持動態(tài)裝載和卸載;
模塊分類:
核心模塊:core module
標(biāo)準(zhǔn)模塊:
HTTP modules:
?????Standard HTTP modules
Optional HTTP modules
????????Mail modules
????????Stream modules:
傳輸層代理
????????3rd ?party modules
Nginx的功能:
靜態(tài)的web資源服務(wù)器;(圖片服務(wù)器,或js/css/html/txt等靜態(tài)資源服務(wù)器)
結(jié)合FastCGI、uwSGI等協(xié)議反代動態(tài)資源請求;
http/https協(xié)議的反向代理;
Imap4/pop3協(xié)議的反向代理;
Tcp/udp協(xié)議的請求轉(zhuǎn)發(fā);
nginx的安裝配置:
官方的預(yù)制包:
http://nginx.org/packages/centos/7/x86_64/
?????????Fedora-EPEL:
編譯安裝:
~]# yum groupinstall "Development Tools" "Server Platform Development"
~]# yum install pcre-devel openssl-devel zlib-devel
~]# useradd -r nginx
~]#./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_dav_module --with-http_stub_status_module --with-threads --with-file-aio
# make && make install
程序環(huán)境:
配置文件的組成部分:
主配置文件:nginx.conf
?????Include conf.d/*.conf
Fastcgi, uwsgi,scgi等協(xié)議相關(guān)的配置文件
Mime.types:支持的mime類型
主程序文件:/usr/sbin/nginx
Unint File: nginx.service
配置:
主配置文件的配置指令:
Directive value [value2 ...];
注意:
(1)指令必須以分號結(jié)尾;
(2)支持使用配置變量;
自建變量:由Nginx模塊引入,可直接引用;
自定義變量:由用戶使用set命令定義;
?????????????????Set variable_name value;
引用變量:$variable_name
下邊是主配置文件結(jié)構(gòu):
Main block:主配置段,也即全局配置段;
?????????????????Event ?{
?????????????????????????......
}:事件驅(qū)動相關(guān)的配置 ??
????????????http ?{
??????????????????......
}:http/httpd協(xié)議相關(guān)的配置段;
Mail {
????...... ??
}
Stream {
???......
}
http協(xié)議相關(guān)的配置結(jié)構(gòu)
?????????http {
????????????...
...:各server的公共配置
Server {
??...
}:每個server用于定義一個虛擬主機;
Server {
?????...
????Listen
????Server_name
????Root
????Alias
????Location [OPERATOR] URL {
??????...
?????If CONDITION {
????????...
}
}
}
}