[root@test sbin]# ./tengine -v
Tengine version: Tengine/2.0.1 (nginx/1.4.6)
#参考地址
user root root;
#工作进程数
worker_processes auto;
#CPU总核数或者总核数2倍
worker_cpu_affinity auto;
#进程id
pid /usr/local/tengine/nginx.pid;
#描述文件数量
worker_rlimit_nofile 102400;
events
{
#设置网络I/O模型.Linux为epoll
use epoll;
#允许连接数
worker_connections 102400;
}
http
{
include mime.types;
default_type application/octet-stream;
fastcgi_intercept_errors on;
#设置字符集
charset utf-8;
#保存服务器名字的hash表是由指令server_names_hash_max_size
#和server_names_hash_bucket_size所控制的。参数hash bucket size总是等于hash表的大小,
#并且是一路处理器缓存大小的倍数。在减少了在内存中的存取次数后,使在处理器中加速查找hash表键值成为可能。如果hash bucket size等于一路处理器缓存的大小,那么在查找键的时候,最坏的情况下在内存中查找的次数为2。第一次是确定存储单元的地址,第二次是在存储单元中查找键 值。因此,如果Nginx给出需要增大hash max size
#或 hash bucket size的提示,那么首要的是增大前一个参数的大小
server_names_hash_bucket_size 128;
#客户端请求头部的缓冲区大小,这个可以根据你的系统分页大小来设置,
#一般一个请求的头部大小不会超过1k,不过由于一般系统分页都要大于1k,所以这里设置为分页大小。分页大小可以用命令getconf PAGESIZE取得。
#使用getconf PAGESIZE获得大小
client_header_buffer_size 4k;
large_client_header_buffers 8 128k;
#设置客户端上传文件大小
client_max_body_size 300m;
#/sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,
#对于普通应用,必须设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,
#以平衡磁盘与网络I/O处理速度,降低系统的uptime.
sendfile on;
#tcp_nopush与 tcp_nodelay 互相排斥
tcp_nopush on;
keepalive_timeout 60;
#tcp没有延迟。接受之后。立刻发送、设置为on组合为更大的帧发送。
tcp_nodelay off;
#设置缓存区的最大值
#Sets buffer size for reading client request body. In case the request body is larger than the buffer, the whole body or only its part is written to a temporary file. By default, buffer size is equal to two memory pages. This is 8K on x86,
#other 32-bit platforms, and x86-64. It is usually 16K on other 64-bit platforms.
client_body_buffer_size 512k;
#Defines a timeout for establishing a connection with a proxied server.
#It should be noted that this timeout cannot usually exceed 75 seconds.
#最大值不超过75s
proxy_connect_timeout 5;
#设置默认值60秒
#Defines a timeout for reading a response from the proxied server. The timeout is set only between two successive read operations, not for the transmission of the whole response.
# If the proxied server does not transmit anything within this time, the connection is closed.
proxy_read_timeout 60;
#Sets a timeout for transmitting a request to the proxied server. The timeout is set only between two successive write operations, not for the transmission of the whole request.
#If the proxied server does not receive anything within this time, the connection is closed.
proxy_send_timeout 60;
#设置proxy_buffer_size与 proxy_buffers值相等等于linux平台上getconf PAGESIZE
#Sets the number and size of the buffers used for reading a response from the proxied server,
#for a single connection. By default,
#the buffer size is equal to one memory page. This is either 4K or 8K,
# depending on a platform.
#以下三个参数保持一致
proxy_buffer_size 8k;
proxy_buffers 8 8k;
#设置为值必须大于proxy_buffers与proxy_buffer_size
proxy_busy_buffers_size 8k;
#当buffer放不下的时候写入文件的大小
proxy_temp_file_write_size 64k;
#设置文件路径
proxy_temp_path /usr/local/tengine/temp;
#设置缓存名字为cache_one;大小是200M;最大值是30G;保留时间1天。保存双份。
#proxy_cache cache_one;加入到location当中;可以启用cache:
如图:
proxy_cache_path /usr/local/tengine/cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;
#启动压缩
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#设置日志格式
log_format main '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $request_time $remote_addr';
#负载均衡设置
#权重1.运行失败次数3次,失败超时30s;
upstream resinServer {
server 192.168.0.28:31201 weight=1 max_fails=3 fail_timeout=60s;
server 192.168.0.28:31202 weight=1 max_fails=3 fail_timeout=60s;
server 192.168.0.61:31203 weight=1 max_fails=3 fail_timeout=60s;
server 192.168.0.61:31204 weight=1 max_fails=3 fail_timeout=60s;
#Tabbao的Tengine的特殊设置
#载录自http://tengine.taobao.org/document_cn/http_upstream_check_cn.html
Syntax: check interval=milliseconds [fall=count] [rise=count] [timeout=milliseconds] [default_down=true|false] [type=tcp|http|ssl_hello|mysql|ajp] [port=check_port]
Default: 如果没有配置参数,默认值是:interval=30000 fall=5 rise=2 timeout=1000 default_down=true type=tcp
Context: upstream
该指令可以打开后端服务器的健康检查功能。
指令后面的参数意义是:
interval
:向后端发送的健康检查包的间隔。
fall
(fall_count): 如果连续失败次数达到fall_count,服务器就被认为是down。
rise
(rise_count): 如果连续成功次数达到rise_count,服务器就被认为是up。
timeout
: 后端健康请求的超时时间。
default_down
: 设定初始时服务器的状态,如果是true,就说明默认是down的,如果是false,就是up的。默认值是true,也就是一开始服务器认为是不可用,要等健康检查包达到一定成功次数以后才会被认为是健康的。
type
:健康检查包的类型,现在支持以下多种类型
tcp
:简单的tcp连接,如果连接成功,就说明后端正常。
ssl_hello
:发送一个初始的SSL hello包并接受服务器的SSL hello包。
http
:发送HTTP请求,通过后端的回复包的状态来判断后端是否存活。
mysql
: 向mysql服务器连接,通过接收服务器的greeting包来判断后端是否存活。
ajp
:向后端发送AJP协议的Cping包,通过接收Cpong包来判断后端是否存活。
port
: 指定后端服务器的检查端口。你可以指定不同于真实服务的后端服务器的端口,比如后端提供的是443端口的应用,你可以去检查80端口的状态来判断后端健康状况。默认是0,表示跟后端server提供真实服务的端口一样。该选项出现于Tengine-1.4.0。
#设置3秒检查一次。次数达到5次认为down.成功尝试3次认为up.服务类型是http类型;
#是代理Resin所以使用了http协议。
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_http_send "GET / HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
#Session机制。注意Session_sticky 没有ip_hash;稳定
#但是ip_bash.必须保证后端是真实服务器,不可以是squid之类的代理服务器
#session_sticky;
#活动链接保持30秒超时
keepalive_timeout 30s;
#解决不同用户登陆浏览器,可用独立使用Session。
#避免串号现象:即不同用户登陆,后一次登陆使用了前一次的菜单信息
ip_hash;
}
server {
listen 80;
server_name 192.168.0.28;
#轮询页面顺序
index login.jsp index.jsp;
root /opt/resin-pro-3.0.27/webapps/test
location / {
proxy_pass http://resinServer;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#静态页面缓存有效期是1天
location ~ .*\.(css|htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
{
expores 1d;
}
location ~ .*\.(jsp|do|class|js)$
{
proxy_pass http://resinServer;
}
location /status{
check_status ;
access_log off;
}
access_log /usr/local/tengine/logs/access.log main;
error_log /usr/local/tengine/logs/error.log crit;