nginx高效能配置的幾個重要引數(java web應用)
阿新 • • 發佈:2020-07-13
網際網路上講述nginx高併發配置的比較多,主要是nginx+php。本博講述nginx java web應用配置,實現高併發。
配置cpu核數
worker_processes 10;
worker_rlimit_nofile 102400;
配置epoll網路模型worker_connections執行緒數,開到上萬
events {
use epoll;
worker_connections 10240;
multi_accept on;
}
圖片資源cache
http{
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;
#控制緩衝區溢位攻擊
client_body_buffer_size 1K;
client_header_buffer_size 1k;
client_max_body_size 1k;
large_client_header_buffers 2 1k;
##cache##
proxy_connect_timeout 5;
proxy_read_timeout 60;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
gzip_proxied any;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_temp_path /home/temp_dir;
proxy_cache_path /home/cache levels=1:2 keys_zone= <span style="color:#ff0000;"><strong>cache_one</strong></span>:200m inactive=1d max_size=1g;
#gzip#
gzip on;
gzip_vary on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 4;
gzip_http_version 1.0;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_disable "MSIE [1-6]\.";
}
#圖片前端快取
location ~ .*\.(jsp|do|action)?$
{
# $server_port 可以不要,只有nginx的埠是非80情況下有效
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://tc;
}
location ~ .*\.(gif|jpg|png|htm|html|css|flv|ico|swf) {
proxy_pass http://tc;
proxy_redirect off;
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $host;
proxy_cache <span style="color:#ff0000;"><strong>cache_one</strong></span>;
proxy_cache_valid 200 302 1h;
proxy_cache_valid 301 1d;
proxy_cache_valid any 1m;
expires 30d;
}
location ~ .*\.(js)?$
{
expires 1h;
}
linux作業系統配置
vi /etc/sysctl.conf增加或者修改引數
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.nf_conntrack_max = 655360
net.netfilter.nf_conntrack_tcp_timeout_established = 1200
kernel.shmall=4294967296
net.ipv4.tcp_max_tw_buckets=6000
vi /etc/security/limits.conf
* soft nofile 1024000
* soft nproc 1024000
* hard nofile 1024000
* hard nproc 1024000