ab -n 请求数 -c 并发数 请求url
Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一个IMAP/POP3/SMTP服务。javascript
Mainline version 开发版(有更新的功能,但不必定稳定)
Stable version 稳定版(通过测试,有更好的稳定性)
Legacy version 历史版本css
#运行用户 user nobody; #启动进程,一般设置成和cpu的数量相等 worker_processes 1; #全局错误日志及PID文件 #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; #工做模式及链接数上限 events { #epoll是多路复用IO(I/O Multiplexing)中的一种方式, #仅用于linux2.6以上内核,能够大大提升nginx的性能 use epoll; #单个后台worker process进程的最大并发连接数 worker_connections 1024; # 并发总数是 worker_processes 和 worker_connections 的乘积 # 即 max_clients = worker_processes * worker_connections # 在设置了反向代理的状况下,max_clients = worker_processes * worker_connections / 4 为何 # 为何上面反向代理要除以4,应该说是一个经验值 # 根据以上条件,正常状况下的Nginx Server能够应付的最大链接数为:4 * 8000 = 32000 # worker_connections 值的设置跟物理内存大小有关 # 由于并发受IO约束,max_clients的值须小于系统能够打开的最大文件数 # 而系统能够打开的最大文件数和内存大小成正比,通常1GB内存的机器上能够打开的文件数大约是10万左右 # 咱们来看看360M内存的VPS能够打开的文件句柄数是多少: # $ cat /proc/sys/fs/file-max # 输出 34336 # 32000 < 34336,即并发链接总数小于系统能够打开的文件句柄总数,这样就在操做系统能够承受的范围以内 # 因此,worker_connections 的值需根据 worker_processes 进程数目和系统能够打开的最大文件总数进行适当地进行设置 # 使得并发总数小于操做系统能够打开的最大文件数目 # 其实质也就是根据主机的物理CPU和内存进行配置 # 固然,理论上的并发总数可能会和实际有所误差,由于主机还有其余的工做进程须要消耗系统资源。 # ulimit -SHn 65535 } http { #设定mime类型,类型由mime.type文件定义 include mime.types; default_type application/octet-stream; #设定日志格式 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; #sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件, #对于普通应用,必须设为 on, #若是用来进行下载等应用磁盘IO重负载应用,可设置为 off, #以平衡磁盘与网络I/O处理速度,下降系统的uptime. sendfile on; #tcp_nopush on; #链接超时时间 #keepalive_timeout 0; keepalive_timeout 65; tcp_nodelay on; #开启gzip压缩 gzip on; gzip_disable "MSIE [1-6]."; #设定请求缓冲 client_header_buffer_size 128k; large_client_header_buffers 4 128k; #设定虚拟主机配置 server { #侦听80端口 listen 80; #定义使用 www.nginx.cn访问 server_name www.nginx.cn; #定义服务器的默认网站根目录位置 root html; #设定本虚拟主机的访问日志 access_log logs/nginx.access.log main; #默认请求 location / { #定义首页索引文件的名称 index index.html index.htm; 若是能找到指定的 uri 那么就返回相应的内容,不然的话返回错误状态码 404 try_files $uri $uri/ =404; } # 定义错误提示页面 error_page 500 502 503 504 /50x.html; location = /50x.html { } #静态文件,nginx本身处理 location ~ ^/(images|javascript|js|css|flash|media|static)/ { #过时30天,静态文件不怎么更新,过时能够设大一点, #若是频繁更新,则能够设置得小一点。 expires 30d; } #禁止访问 .htxxx 文件 location ~ /.ht { deny all; } } }
arg_PARAMETER
http_HEADER(如:http_user_agent)
sent_http_HEADERhtml
http_sub_status_module nginx客户端的状态(能够配置在server和location下)java
stub_status;
具体使用结果:https://blog.csdn.net/echizao...
http_sub_module HTTP内容替换(http|server|location)node
sub_filter string(要替换的内容) replacement(替换的内容); sub_filter_once off;默认为on 默认匹配全部内容,on只匹配一次 sub_filter_last_modified on;默认为off 判断服务器文件是否发生过变动,不变动则不从新加载
http_random_index_module 目录中选择一个随机主页(配置在location中)linux
random_index on;默认为off
limit_conn_module 链接频率限制nginx
limit_conn_zone key zone=name:size;(http) limit_conn zone number;(http|server|location)
limit_req_modele 请求频率限制服务器
limit_req_zone key zone=name:size rate=rate;(http) 如:limit_req_zone $binary_remote_addr zone=req_zone:1m rate=1r/s; limit_req zone=name [burst=number](延迟数) [nodelay];(http\server\location)
http_access_module 基于ip的控制访问(经过$remote_addr实现,代理模式就失去了做用,x-forword-for,geo模块,自定义变量解决)网络
allow address | CIDR(网段) | unix: | all;(http\server\location\limit_except) deny address | CIDR | unix: | all;(http\server\location\limit_except)
http_auth_basic_module 基于用户的信任登陆(弊端解决:1结合lua实现高效验证,2利用nginx-auth-ldap模块,实现nginx和ldap打通)并发
auth_basic string | off;默认off(http\server\location\limit_except); auth_basic_user_file file;(http\server\location\limit_except); file为一个用户名密码文件 file生成方式:htpasswd -c 文件名 用户名 而后就会让输入两次密码 命令在httpd-tools中