1. nginx由内核和模块组成,内核设计非常微小简洁,根据客户端请求匹配相应模块完成相应的工作。


nginx模块分为核心模块、基础模块、第三方模块。

核心模块:http模块、event模块、mail模块

基础模块:http access模块、http fastcgi模块、http proxy模块、http rewrite模块

第三方模块:http upstream request hash模块、notice模块、http access key 模块


模块功能分为三类:

Handlers 处理器模块

Filters 过滤器模块

Proxies 代理模块

2.nginx安装(略)


3.nginx配置文件介绍


nginx的配置文件是一个纯文本文件,它一般位于nginx的安装目录的conf目录下,整个配置文件是以block的形式组织的。每个block一般以一个大括号“{ }”来表示、

block可以分为几个层次。

整个配置文件中Main命令位于最高层,在Main层下可以有Event、Http等层级。

而Http层中又包含Server层,即server block,server block中又可分为location层,并且一个server block中可以包含多个location block。


Main(全局设置)     设置的命令影响全局

server(主机设置)     主要用于指定主机和端口

upstream(负载均衡服务器设置)     主要用于负载均衡,设置一系列后端服务器

location(URL 匹配特定位置的设置)     用于匹配网页位置


四者之间的关系式    server继承main ,location继承server ,upstream既不会继承其他设置也不会被继承。


nginx.conf文件内容如下:


user nobody nobody;

worker_processes 4;

error_log logs/error.log notice;

pid logs/nginx.pid

worker_rlimit_nofile 65535;

events{


     use epoll;

     woker_connections 65535;

}

日志级别:debug、info、notice、warn、error、crit   其中debug最为详细,crit输出日志最少。


events:设置nginx的工作模式及连接数上限。

工作模式:select poll kqueue epoll rtsig 

客户端最大连接数由 worker_processes 和 worker_connections决定,即max_client=worker_process * worker_connections.

进程的最大连接数受linux系统进程的最大打开文件数限制,使用ulimit -n 65536 设置


nginx http 属性配置:

http {


include conf/mime.types;

default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] '

    '"$request" $status $bytes_sent '

    '"$http_referer" "$http_user_agent" '

    '"$gzip_ratio"';

access_log logs/www.test.com.access.log main;


client_max_body_size 20m;

client_header_buffer_size 32k;

large_client_header_buffers 4 128k;

sendfile on;

tcp_nopush    on;

tcp_nodelay    on;

keepalive_timeout    60;

client_header_timeout    10;  #nginx 返回 request time out ( 408 ) 说明请求头读取超过此时间

client_body_timeout    10;

send_timeout    10;


.....................................


}


下章讲解nginx 虚拟主机配置