#$ 开头是变量
#定义Nginx 运行的用户和用户组
user work work;
#Nginx进程数, 建议设置为CPU 总核心数
worker_processes auto;
# 指当一个Nginx 进程打开的最多文件描述符数目
worker rlimit nofile 204800;
# 全局错误日志定义类型, [ debug | info | notice | warn | error | crit ]
error_log /opt/log/nginx/error.log error;
# 工作模式及连接数上限
events {
#参考事件模型, use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];
#epoll 模型是Linux 2.6 以上版本内核中的高性能网络工/ 0 模型,如果运行在FreeBSD 上面,
#就用kqueue 模型
use epoll;
#单个后台worker process 进程的最大并发连接数
worker_connections 102400;
}
#设定http 服务器,利用它的反向代理功能提供负载均衡支持
http {
# 文件扩展名与文件类型映射表
include mime.types;
# 默认文件类型
default_type application/octet-stream;
# 默认编码
charset utf-8;
# 设定日志格式
#log_format main ’$idXXXX\t$remote_addr\t$remote_user\t $time_local\t$http_host\t$request\t'
# ’$status\t$body_bytes_sent\t$http_referer\t ’
# ’$http_user_agent\t$http_x_forwarded_for\t$request_time\t$upstream_response_time\t$userid’;
log_format main "$cookie_idXXXX\t$remote_addr\t$remote_user\t[$time_local]\t$request_method\t$host\t$request_uri\t”
”$request_time\t$status\t$body_bytes_sent\t’$http_referer'\t”
"'$http_user_agent’\t’$http_x_forwarded_for’\t$upstream_addr\t$upstream_response_time\t$upstream_status\t”;
# 不可见字符分隔日志格式
#include other log forrnat.conf;
# 实时日志收集JSON 格式日志
#include json_log_forrnat.conf;
# 日志流格式
log_format stream_log "$cookie_idXXXX\t$remote_addr\t$remote_user\t($time_local]\t$request_method\t$host\t$request_uri\t”
”$request_time\t$status\t$body_bytes_sent\t’$http_referer’\t" “'$http_user_agent'\t'$http_x_forwarded_for’\t$upstream_addr\t$upstream_response_time\t3”;
# 成功日志
access_log /opt/log/nginx/access.log main;
#access_log syslog:local6:notice:logl.op.XXXXdns.org:514:nginx-main-logmain;
# 指定Nginx 是否调用sendfile 函数( zero copy 方式)来输出文件,对于普通应用,
# 必须设为on ,如果用来进行下载等应用磁盘I/O重负载应用,可设置为off ,以平衡磁盘与网络I/O处理速度,降低系统的uptime
sendfile on;
# 长连接超时时间, 单位是秒
keepalive_timeout 60;
# 服务器名称hash 表的最大值{ 默认512)[hash%size]
server_names_hash_max_size 1024;
# 服务器名字的哈希表大小
server_names_hash_bucket_size 256;
# 客户请求头缓冲大小
client_header_buffer_size 4k;
# 如果header 过大,它会使用large_client_header_buffers来读取
large_client_header_buffers 4 256k;
client_header_timeout 1m;
client_body_timeout 1m;
send_timeout 1m;
#防止网络阻塞
tcp_nopush on;
tcp_nodelay on;
#允许客户端请求的最大单文件字节数
client_max_body_size 50m;
# 缓冲区代理缓冲用户端请求的最大字节数
client_body_buffer_size 50m;
#Nginx 跟后端服务器连接超时时间( 代理连接超时)
proxy_connect_timeout 5;
# 后端服务器数据回传时间( 代理发送超时)
proxy_send_timeout 15;
# 连接成功后, 后端服务器响应时间( 代理接收超时)
proxy_read_timeout 15;
# 设置代理服务器( Nginx )保存用户头信息的缓冲区大小
proxy_buffer_size 4k;
#proxy_buffers 缓冲区, 网页平均在32KB 以下的话, 这样设置
proxy_buffers 8 32k;
# 高负荷下缓冲大小( proxy buffers*2 )
proxy_busy_buffers size 64k;
# 设定缓存文件夹大小, 大于这个值, 将从upstream 服务器传
proxy_temp_file_write_size 64k;
proxy_intercept_errors on;
# 客户端放弃请求, Nginx 也放弃对后端的请求
#proxy_ignore_client_abort on;
# 代理缓存头信息最大长度[ 设置头部哈希表的最大值, 不能小于后端服务器设置的头部总数]
proxy_headers_hash_max_size 512;
# 设置头部hash表大小( 默认64 )[ 这将限制头部字段名称的长度大小, 如果使用超过64个字符的头
部名可以加大这个值。]
proxy_headers_hash_bucket_size 256;
# 变量hash表的最大值( 默认值}
variables_hash_max_size 512;
# 为变量hash 表设置关键字栏的大小( 默认64)
variables_hash_bucket_size 128;
# 开启gzip 压缩输出
gzip on;
# 最小压缩文件大小
gzip_min_length 1k;
# 压缩缓冲区
gzip_buffers 4 16k;
# 压缩等级
gzip_comp_level 9;
# 压缩版本(默认1.1 ,前端如果是squid2.5 , 则使用1. 0 )
gzip http_version 1.0;
# 压缩类型, 默认就已经包含texthtml
gzip_types text/plain application/x-javascript application/json application/javascript text/css application/xml text/javascript image/gif image/png;
gzip_vary on;
#map 模块的使用
map_hash_max_size 102400;
map_hash_bucket_size 256;
#Tengine Config
#concat on;
#trim on;
#trim_css off;
#trim_js off;
server_tokens off;
#footer ”<!-- $remote_addr $server_addr $upstream_addr --> ”;
#rewrite log on;
fastcgi_intercept_errors on;
#include other config file
include .. /conf.d/*.conf;
# 包含一些特殊站点的配置文件,此目录下文件暂时不包含在git 自动管理过程中
include .. /special/*.conf;
# 屏蔽不加主机域名的默认请求
#server {
# listen *:80 default;
# server_name _ ””;
# return 444;
#}
#Nginx 状态监测模块配置
req_status_zone server ” $server_name,$server_addr:$server_port" 1OM;
req_status server;
server {
listen 127.0.0.1:80;
server_name 127.0.0.1;
access_log /opt/log/nginx/nginx_status/status_access.log main;
location /status {
req_status_show;
access_log /opt/log/nginx/nginx_status/status_access.log main;
allow 127.0.0.1;
deny all;
}
location /stub_status {
stub_status on;
access_log /opt/log/nginx/nginx_status_stub/status_stub_access.
log main;
allow 127.0.0.1;
deny all;
}
location /check_status {
check_status;
access_log /opt/log/nginx/nginx_status_check/status_access_check.log main;
allow 127.0.0.1;
deny all;
}
}
}