user nobody nobody; //以普通身份运行nginx
worker_processes 4; //打开的进程数
worker_rlimit_nofile 51200; //所能够同时打开的文件数
error_log logs/error.log notice; //错误日志文件
pid /var/run/nginx.pid; //pid文件
event {
use epoll; //使用epoll事件驱动
worker_connections 51200; //每一个进程所能够承受的连接数
}
http {
server_tokens off; //关闭信息详细显示,防止信息泄露
include mime.types;
proxy_redirect off; //是否proxy做重定向
proxy_set_header Host $host; //如果有虚拟主机,后端也能转发
proxy_set_header X-Real-IP $remote_addr; //将真正请求的客户端IP发往后端
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; //日志中记录转发的每一级代理服务器
client_max_body_size 20m; //所能够接受的客户端最大的请求主体部分的大小
client_body_buffer_size 256k; //内存中缓存
proxy_connect_timeout 90; //向后端服务器发起连接请求的超时时间
proxy_send_timeout 90; //向后端服务器发送请求报文的超时时间
proxy_read_timeout 90; //读取后端服务器响应报文的超时时间
proxy_buffer_size 128k; //代理服务器的buffer大小
proxy_buffers 4 64k; //有多少个buffer,表示4段缓存空间,每段64k
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
default_type application/octet-stream;
charset utf-8;
client_body_temp_path /var/tmp/client_body_temp 1 2;
proxy_temp_path /var/temp/proxy_temp 1 2;
fastcgi_temp_path /var/tmp/fastcgi_temp 1 2;
uwsgi_temp_path /var/tmp/uwsgi_temp 1 2;
scgi_temp_path /var/tmp/scgi_temp 1 2;
ignore_invalid_headers on; //忽略不合法的不理解的首部信息
server_names_hash_max_size 256; //将每个server的名字放到内存中进行hash,用户请求的时候根据内存中hash的值进行比较
server_names_hash_bucket_size 64;
client_header_buffer_size 8k; //客户端请求首部用多大内存缓存下来进行分析
large_client_header_buffers 4 32k;
connection_pool_sie 256;
request_pool_size 64k;
output_buffers 2 128k;
postpone_output 1460;
client_header_timeout 1m;
client_body_timeout 3m;
send_timeout 3m;
log_format main '$server_addr $remote_addr [$time_local] $msec+$connection' //服务器端地址 客户端地址 日志本地时间 毫秒级的解析度获取的当前时间加上连接建立所经过的时间
'"$request" $status $connection $request_time $body_bytes_sent "$http_referer"' //用户请求的url 响应码
'"$http_user_agent" "$http_x_forwarded_for"';
open_log_file_cache max=1000 inactive=20s min_users=1 valid=1m; //打开日志文件缓存
access_log logs/access.log main;
log_not_found on;
sendfile on;
tcp_nodelay on;
tcp_nopush off;
reset_timedout_connection on;
keepalive_timeout 10 5;
keepalive_requests 100;
gzip on;
gzip_http_version 1.1;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_proxied expired no-cache no-store private auth no_last_modified no_etag;
gzip_types text/plain application/x-javascript text/css application/xml application/json;
gzip_disable "MISE[1-6].(?!.*SV1)";
upstream tomcat8080 {
ip_hash; //session保持
server 172.16.100.103:8080 weight=1 max_fails=2;
server 172.16.100.104:8080 weight=1 max_fails=2;
server 172.16.100.105:8080 weight=1 max_fails=2;
}
server{
listen 80;
server_name www.magedu.com;
#config_apps_begin
root /data/webapps/htdocs;
access_log /var/logs/webapp.access.log main;
error_log /var/logs/webapp.error.log notice;
}
location / {
location ~* ^.*/favicon.ico$ {
root /data/webapps;
expires 180d;
break;
}
if(!-f $request_filename){
proxy_pass http://tomcat8080;
break;
}
}
error_page 500 502 503 504 /50x.html;
location=/50x.html {
root html;
}
}
server{
listen 8080;
server_name nginx_status;
location / {
access_log off;
deny all;
return 503;
}
location /status {
stub_status on;
access_log off;
allow 127.0.0.1;
allow 172.16.100.71;
deny all;
}
}
}