user nginx nginx;
worker_processes 4; #启动的进程数
worker_rlimit_nofile 51200; #所能够打开的文件数
error_log logs/error.log notice;
pid /var/run/nginx.pid;
events {
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_xforwarded_for; #记录代理经过的节点
client_max_body_size 20m; #最大能够接收客户端请求主体为20m
client_body_buffer_size 256k; #内存中的缓冲大小,不要太大,并发量高将导致内存爆满
proxy_connect_timeout 90; #向后端服务器请求连接的超时时长
proxy_send_timeout 90; #向后端服务器发送请求报文的超时时长
proxy_read_timeout 90; #读取后端服务器响应报文的超时时长
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_bosy_temp 1 2;
proxy_temp_path /var/tmp/proxy_temp 1 2;
fastcgi_temp_path /var/tmp/fastcgi_temp 1 2;
uwsgi_temp_path /var/tmp/uwcgi_temp 1 2;
scgi_temp_path /var/tmp/scgi_temp 1 2;
#存储临时文件目录,1 2为定义子目录字符数,一级子目录一个字符 二级子目录两个字符
ignore_invalid_headers on; #是否忽略不能识别的首部
server_names_hash_max_size 256;
server_names_hash_bucket_size 64; #将server name进行hash,保存在内存中
client_header_buffer_size 8k;
large_client_header_buffers 4 32k;
connection_pool_size 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 '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#定义日志
open_log_file_cache max=1000 inactive=20s min_uses=1 valid=1m;
#日志缓存,记录1000条日志,一并写入日志文件。非活动期限为20s,做少要使用多少次 有效期为1m;
access_log logs/access.log main; #日志文件保存位置
log_not_found on; #是否在error_log中记录不存在的错误。(用户响应为Not Found)
sendfile on;
tcp_nodelay on;
tcp_nopush on;
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_min_length 1024;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_proxied expired no-cache no-store auth no_last_modified no_etag;
gzip_types text/plain application/x-javascript test/css application/xml application/json;
gzip_disable "MSIE[1-6]\.(?!.*SV1)";
upstream tomcat8080 {
ip_hash;
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;
#权重都为1,最大失败次数为2
}
}
server {
listen 80;
server_name blog.beijixs.cn;
root /data/webapps/htdocs;
access_log /var/logs/webapp.access.log main;
error_log /var/logs/webapps.error.log notice;
location / {
location ~* ^.*/favicon.ico$ {
root /data/webapps;
expires 180d; #页面图标缓存180天
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 8088;
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;
} #只允许指定ip访问
}
下载地址回复可见:
此处内容需要评论回复后(审核通过)方可阅读。
<center>END</center>